var arr = [1,2,3];
var o = [];
for(var i = 0; i<arr.length;i++) {
var val = arr[i];
o.push(function(){ alert(val); });
}
o.forEach(function(func){ func(); });
array comprehensions
var arr = [1, 2, 3, 4];
var doubled = [for (x of arr) 2*x];
doubled.forEach(alert);
lamda / fat arrow
'use strict';
var double = (x) => x * 2;
alert(double(10));
/*
var alertHandle;
var obj = {
twitter: 'johnkpaul',
init: function(){
alertHandle = () =>
alert(this.twitter);
}
};
obj.init();
alertHandle();
*/
destructuring assignment
var arr = [1, 2, 3];
func(arr);
function func([fst, snd, thd]){
alert(fst);
alert(thd);
}
/* REST PARAMETERS vvv
function destructure(...args){
var [options, callback] = args;
alert(options.v);
alert(typeof callback);
}
var o = {v: true}
destructure(o, () => $.noop);
*/
template strings
var first = "John K."
var last = "Paul";
var t = `I'm ${first} ${last}!`;
alert(t);
function* inf(){
var i = 0;
while(true){
yield ++i;
}
}
for(var x of inf()){
alert(x);
if(x > 3) { break; }
}