| 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}, how are you ${time}?`
Why aren't we just using #{} like everyone else? // Construct an HTTP request prefix is used to interpret the replacements and construction
GET`http://foo.org/bar?a=${a}&b=${b}...
What??Destructuring: var [a, , b] = [1,2,3];
Is that seriously just whitespace and another comma?Splats (spreads?) f(...[1,2,3]) == 6
... means destructure?This is not readable code: let fibonacci = {
[Symbol.iterator]() {
let pre = 0, cur = 1;
return {
next() {
[pre, cur] = [cur, pre + cur];
return { done: false, value: cur }
}
}
}
}
for (var n of fibonacci) {
// truncate the sequence at 1000
if (n > 1000)
break;
print(n);
}
Symbols without a literal syntax: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
Jesus Christ.Unicode: "𠮷".length == 2
Awesome, still wrong.Modules are cool.
Promises are cool.
Tail call optimization is cool. This is not readable code: // Proxying a normal object
var target = {};
var handler = {
get: function (receiver, name) {
return `Hello, ${name}!`;
}
};
var p = new Proxy(target, handler);
p.world === 'Hello, world!';
ES6 is a mess. Javascript just got harder. |
Again not surprising, a leading `=>` would be a syntax error so `()` is an obvious compromise which can be naturally be extended to add args, e.g:
> Seriously another String delimiter? Yep, String interpolation is incredibly useful especially in JavaScript which does a lot of string munging - this will lead to more succinct, readable code. Should be obvious why they didn't want to break existing JS by re-using "" double-quotes.> Why aren't we just using #{} like everyone else?
Who's everyone else (Ruby inspired langs)? Scala uses ${1 + 1} or $var shorthand (same as Groovy, Kotlin, JSP EL, Haxe), C# 6 uses {var}, Swift uses \(var) whilst Python and Java have string formats that use %(var)
> Is that seriously just whitespace and another comma?It's clearly ignoring matching the second element. Some languages choose to use `_` as a special ignore placeholder, JavaScript chose not to. Either way is not unintuitive with what it does so that's ok.
The other features are extremely useful if you need them, otherwise you can happily ignore them and use the subset you're comfortable with.