In Response to http://qfox.nl/weblog/282
Peter van der Zee published this post on his personal blog and it was featured in this week's edition of JavaScript Weekly. The following sections each contain a piece of code copied directly from his post, followed by an irrefutable explanation of why it is either wrong or misleading.
EDIT, April 1, 2013: I've removed any harsh language, but the content and corrections remain the same.
{ [foo](bar) { } }
On the table, but not definite. Also, this isn't legal syntax, it's a block body with non-sense in it, that isn't legal today or even in ES6 with concise methods.
Assuming there is some issue with concise methods, from the previous example...
{ [foo](bar) { } }
However, to illustrate concise methods, this is more appropriate:
var o = {
method() {
console.log("hi!");
}
};
o.method();
let { first: f, last: l } = {first:'Jane', last:'Doe'};
let { first, last } = { first: 'Jane', last: 'Doe' };
[x,y] = [y,x];
I disagree that this is hard to understand, but anything new will require some amount of time investment to fully grok.
The first binds f
and l
identifiers that have the values of the object's first
and last
properties.
Like this:
var o = {
first: 'Jane',
last: 'Doe'
}, f = o.first, l = o.last;
The second binds first
and last
identifiers that have the values of the object's first
and last
properties.
Like this:
var o = {
first: 'Jane',
last: 'Doe'
}, first = o.first, last = o.last;
The third flips the values at indexes 0 and 1...
friends.forEach(friend => { ... })
Especially with some of it's restrictions, the fact that it's only available in "strict mode" (last I heard)
Wrong, there is no such restriction.
and its implicit return value...
How is this a restriction? Arrow Functions can absolutely have an explicit return—in fact, the form you show requires an explicit return, otherwise returns undefined by default:
[ 1, 2, 3 ].map(x => x * x);
[ 1, 2, 3 ].map(x => { return x * x });
Are a way to create unforgeable, unguessable objects that may be used as a string is used for property names (among other uses)
[sym](arg)
I'll defer to this very real example: https://gist.github.com/rwldrn/5225237
function meh(a,b,...c,{d="hello", e="world"},[f,g],h){
console.log(a,b,c,d,e,f,g,h);
for (num of (for (x of (for (x of [1,2,3]) x)) x*x)) console.log(num);
}
meh(...[1,2,3,4,5,6,7,8,9],[10,11,12]);
Can you figure out the output? I don't even want to bother.
I wouldn't either, because it's not valid. The rest parameter must be the last parameter in the formal parameters list.
a
and b
eat up 1 and 2 (respectively), leaving the remainder of the spread array argument and the second array argument for the rest params as c
[3,4,5,6,7,8,9, [10,11,12]]
.
The generator comprehension outputs:
1
4
9
While the previous versions of ES were mostly backwards compatible, especially in the syntax department...
...As far as I know, this was true for the transitions to ES2 and ES3 as well.
Prior to ES3, none of these existed:
- Function expressions
- Object literal
- Array literal
- try/catch
- do ...while
- switch
- Regexp
- Error
...I'm sure there is more, but this is based on a quick comparison of the two specs.
that I think we should start calling it JS2. Because really, that's what it is.
No, because that would imply that existing code could not run in successfully in ES6 runtimes, which is not true.
they're making JS less like JS.
If that's what you think, then you don't know the spirit of JS.
So confused.
Rick, since when was I so unapproachable that you have to burn me here with sort of personal attacks, rather than tell me this so I could just change this? Just wow man.
Now, let me retort.
Computer properties / concise methods
First you say this isn't valid syntax. Ok, fine. I got that snippet from a tweet by Juriy. But the fact that I'm willing to believe this might/could be valid in ES6....
Then below you say you'll take this example "modified", but it's not modified. The example that follows doesn't relate to the snippet in any way. Can you explain what you meant to do there?
Destructuring
Maybe you could respond to that instead?
Fat arrow
There has certainly been talk about this. And I recall reading this in revision 6 (July?), though I'm going to look that up to confirm, later. If the restriction is out, then great. Is it for other things as well? Is all of es6 available in "sloppy mode"?
Symbols
See Axel's (original) slides, page 28: http://dl.2ality.com/es6.pdf
Rest
I'm pretty sure this wasn't true at some point. But maybe it was just a suggestion that never made it to the spec...
Versions
Okay. I'll keep that in mind.
I believe I do, but I wonder if the tc39 still does.
Now if you'll excuse me, I'm going to enjoy my Easter weekend. Jezus.