Hacker News new | past | comments | ask | show | jobs | submit login
JavaScript proposal: destructuring assignment (ecmascript.org)
26 points by fogus on March 21, 2012 | hide | past | favorite | 8 comments



That link is to a really old ES4 discussion. The proposal for ES6 is at http://wiki.ecmascript.org/doku.php?id=harmony:destructuring and has now been incorporated in the draft ES6 spec.



I 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.


CoffeeScript implements this syntax, and, of course, it's extremely awesome.

http://coffeescript.org/#destructuring


This would be extremely handy. At the moment I'm sometimes even writing

   (function (a, b, c) {/**/}).apply(null, packed);
to emulate destructuring.


Cool, 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...)


Seems like half of the comments are from 6 years ago, am I missing something?


This 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




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: