Combine default parameters and destructuring for a compact version of the defaults / overrides pattern.
function foo ({
bar = 'no',
baz = 'works!'
} = {}) {
#!/usr/bin/env python3 | |
# | |
# Query AWS Athena using SQL | |
# Copyright (c) Alexey Baikov <sysboss[at]mail.ru> | |
# | |
# This snippet is a basic example to query Athen and load the results | |
# to a variable. | |
# | |
# Requirements: | |
# > pip3 install boto3 botocore retrying |
<audio id="alarm" src="alarm.ogg" controls></audio> | |
<script> | |
const alarmElement = document.getElementById('alarm'); | |
const alarmTimes = [ | |
new Date('2015-11-13 07:00 -0500'), | |
new Date('2015-11-13 08:00 -0500'), | |
new Date('2015-11-13 08:30 -0500'), | |
]; | |
function playAlarm() { |
// An `Object.observe()` "polyfill" using ES6 Proxies. | |
// | |
// Current `Object.observe()` polyfills [1] rely on polling | |
// to watch for property changes. Proxies can do one better by | |
// observing property changes to an object without the need for | |
// polling. | |
// | |
// Known limitations of this technique: | |
// 1. the call signature of `Object.observe()` will return the proxy | |
// object. The original object needs to be overwritten with this return value. |
You don't really need a framework or fancy cutting-edge JavaScript features to do two-way data binding. Let's start basic - first and foremost, you need a way to tell when data changes. Traditionally, this is done via an Observer pattern, but a full-blown implementation of that is a little clunky for nice, lightweight JavaScript. So, if native getters/setters are out, the only mechanism we have are accessors:
var n = 5;
function getN() { return n; }
function setN(newN) { n = newN; }
console.log(getN()); // 5
setN(10);
<div ng-app="MyApp"> | |
<h1>Zero padding filter</h1> | |
<div> | |
<input type="text" ng-model="ztext" placeholder="Type some text ..." /> | |
</div> | |
<div> | |
<h2>Result:</h2> | |
<p>{{ztext | zpad:4}}</p> | |
</div | |
</div> |
.container { | |
margin: 0 auto; | |
max-width: 48rem; | |
width: 90%; | |
} |