The Future Of JavaScript
And Why You Should Care
Adam Babik @dreame4
And Why You Should Care
Range.prototype[Symbol.iterator] = function () {
return {
next () {
return { value: val, done: val >= end };
}
};
};
Range.prototype[Symbol.iterator] = function *() {
while (val <= end) {
yield val++;
}
};
You can find much more about generators on David Walsh website.
let arr = [1, 2, 3, 4];
let arrMul2 = arr.map(x => x * 2);
this
var swapArr = ([x, y]) => [y, x];
swapArr([1, 2]); // => [2, 1]
var swapObj = ({ x, y }) => ({ y, x });
swapObj({ x: 1, y: 2 }); // => { x: 2,y: 1 }
// Works with parameters
function len({ x, y }) {
return Math.sqrt(x*x + y*y);
}
var max = (...items) => {
Array.isArray(items); // => true
return Math.max.call(null, ...items);
// like Math.max.apply(null, items);
};
max(14, 3, 13, 12, 9);
$ node build.js && \
node ./arrows.build.js$ node --v8-options | grep harmony