What do you think?
Rate this book
Unknown Binding
Published January 1, 2015
var a = [1,2,3];
[...a.values()]; // [1,2,3]
[...a.keys()]; // [0,1,2]
[...a.entries()]; // [ [0,1], [1,2], [2,3] ]
There's another way to think about this syntax though, which may help ease the confusion. Consider:var aa = 10, bb = 20;
var o = { x: aa, y: bb };
var { x: AA, y: BB } = o;
console.log( AA, BB ); // 10 20
In the { x: aa, y: bb } line, the x and y represent the object properties. In the { x: AA, y: BB } line, the x and the y also represent the object properties.
Recall how earlier I asserted that { x, .. } was leaving off the x: part? In those two lines, if you erase the x: and y: parts in that snippet, you're left only with aa, bb and AA, BB, which in effect -- only conceptually, not actually -- are assignments from aa to AA and from bb to BB.