Should single-line variable swapping work?

Dec 14, 2010 at 7:51 PM
Edited Dec 14, 2010 at 7:52 PM

Paul,

I came across this link which talks about the later versions of ECMAScript supporting single-line variable swapping like this:

a = 1;

b = 2;

[a, b] = [b, a];

This makes a equal to 2 and b equal to 1 without having to have an intermediate variable on the user's part to do the swap.

Did this make it into ECMAScript 5 level or is it beyond that?

Here's a reference link of someone else who mentioned it but not whether or not it was a level 5 thing:

http://www.greywyvern.com/?post=265

Steve

Coordinator
Dec 15, 2010 at 1:01 AM

This feature is called destructuring assignment, and it didn't make it into ECMAScript 5.  However, it has been approved for ECMAScript Harmony, which presumably will be the next major version of the language.

See http://wiki.ecmascript.org/doku.php?id=harmony:destructuring for more information.

- Paul