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
correction - have been moved to ES7
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 alertLoc;
var obj = {
loc: 'Chicago',
init: function(){
alertLoc = () =>
alert("We're in " + this.loc);
}
};
obj.init();
alertLoc();
*/
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; }
}
class Greeter {
constructor(message) {
this.message = message;
}
greet() {
alert(this.message)
}
}
var greeter = new Greeter('Hey');
greeter.greet();
default exports
// a.js
var name = "jqcon";
export default name;
// b.js
import name from "a";
alert(name);
named exports
// a.js
var name = "jqcon";
var location = "Chicago";
export name;
export location;
// b.js
import {location, name} from "a";
alert(name + " is in " + location);
named exports, import namespace
// a.js
var name = "jqcon";
var location = "Chicago";
export name;
export location;
// b.js
import * as a from "a";
alert(a.name + " is in " + a.location);