ECMA 6 - Consider supporting destructuring assignment

Topics: Language Specification
Mar 21, 2013 at 2:45 PM
Edited Mar 21, 2013 at 2:45 PM
I think this would be a nice enhancement to have for the 9.x branch that is not a particularly difficult thing to transpile to ES5, although it may look ugly to some. Apparently Firefox's spidermonkey engine already supports this.
// destructure rvalue array
var [m, d, y] = [3, 21, 2013];

// equivalent to above line
var m = 3, d = 21, y = 2013;
This is also useful for function returns to have ad-hoc tuples:
var [m, d, y] = (function() { return [3, 21, 2013]; })();
And just to take it too far, perhaps this syntax could be [ab]used for an object initialization short hand:
var today : { m, d, y } = ...
Thoughts?
Coordinator
Mar 22, 2013 at 3:51 PM
We're planning to explore adding more ES6 features after the 1.0 release.