views:

43

answers:

3

For a project a developer sent us a .js file with code similar to this:

var myList = [1,2,3];
var a,b,c;

[a,b,c] = myList;

It works in Opera 10.30, Firefox 3.6.x but it's not ok for Opera 10.60 and Chrome.

It's just curiosity, do you have any reference or link that says this code is compliant to JS/ECMA standard or not?

What do you think?

+4  A: 

This is destructuring assignment, available in Javascript 1.7 (mozilla) and some newer browsers: http://www.robertnyman.com/javascript/javascript-1.7.html#destructuring-assignment

Marko Dumic
A: 

JavaScript currently available in all browsers does not support anything but variable=, and object.property= on the left-hand side of expressions.

Its spec is so horrible I won't link to it.

glebm
+1  A: 

This is a feature called destructuring assignment, which was added in JavaScript 1.7. It is not a part of ECMAScript: http://stackoverflow.com/questions/1330498/what-is-cross-browser-support-for-javascript-1-7s-new-features-specifically-arr

ide