ECMAScript 6 is a mess Now there's a completely new function syntax that doesn't use parens and has different scope rules var odds = evens.map(v => v + 1); Enhanced object literals: // Computed (dynamic) property names [ 'prop_' + (() => 42)() ]: 42 what?? So it uses parens if there are no params, but not otherwise? Template Strings: `In JavaScript this is not legal.` Seriously another String delimiter? `Hello ${name…
> Splats (spreads?)
> f(...[1,2,3]) == 6
> ... means destructure?
No, it means something very close to "apply" or "concat", depending on the usage. That example is the same as: f.apply(this, [1,2,3])
But it's cleaner syntax. The interesting part is that you can mix them in anywhere: function f(x, y, z) {
return x + y + z;
}
a = [1,2];
b = [3];
[...a, ...b] == [].concat(a,b) == [1,2,3]
[0, ...a, 4, 5, ...b, 6] == [].concat([0],a,[4,5],b,[6]) == [0,1,2,4,5,3,6]
f(...a, ...b) == 6
f(1, 2, ...b) == 6
f(...a, 3) == 6
f(...b, 0, ...b) == 6
> ES6 is a mess. Javascript just got harder.Want some cheese with that whine? It got more complicated, yes. But I'm liking most of the changes, personally. A lot. Most of them are long overdue.
BTW, if you open Firefox's console, you can try out many examples. Firefox already supports tons of ES6.