3 ms·
JavaScript proposal: destructuring assignment
- fmstephe 15y agoI think this is a great proposal. I would be very happy to see destructuring assignment in JS. In every other language I've used that supports this (Erlang, Clojure) it is a big win.
- antinitro 15y agoSeems like half of the comments are from 6 years ago, am I missing something?
- deleted 15y ago[deleted]
- wingo 15y agoA form of this will probably be in ES6: http://people.mozilla.org/~jorendorff/es6-draft.html#sec-11.13.1 http://people.mozilla.org/~jorendorff/es6-draft.html#sec-11....
- yoklov 15y agoCoffeeScript implements this syntax, and, of course, it's extremely awesome. http://coffeescript.org/#destructuring http://coffeescript.org/#destructuring
- samth 15y agoThat link is to a really old ES4 discussion. The proposal for ES6 is at http://wiki.ecmascript.org/doku.php?id=harmony:destructuring http://wiki.ecmascript.org/doku.php?id=harmony:destructuring and has now been incorporated in the draft ES6 spec.
- VMG 15y agoThis would be extremely handy. At the moment I'm sometimes even writing (function (a, b, c) {/**/}).apply(null, packed); to emulate destructuring.
- Roboprog 15y agoCool, if it gets widespread implementation. Had to read a ways down to see an example to confirm, in simple terms, that this would mean you could make function calls such as: ( a, b, c) = f(); like you would in Perl / Python / Ruby. (not so good at decoding BNF while I'm sipping my first cup of coffee in the morning...)
- Zecc 15y agoThis is something that's been in Firefox's JS way back since FF 2.0. https://developer.mozilla.org/en/New_in_JavaScript_1.7 https://developer.mozilla.org/en/New_in_JavaScript_1.7