Assigning to empty array/object literals

Dmitry A. Soshnikov dmitry.soshnikov at gmail.com
Wed Aug 18 10:38:13 PDT 2010


  On 10.08.2010 9:21, Michael Day wrote:
> Hi,
>
> Firefox 3.6.8 supports the following expressions:
>
> [] = 3;
>
> and:
>
> {} = 3;
>
> Although this object-literal version will trigger a syntax error at 
> block scope, and so needs to be written like this:
>
> x = ({} = 3);
>
> In any case, shouldn't both of these expressions be early syntax 
> errors, as the left hand side can never be a reference?
>
> For comparison, non-empty array and object literals throw an error:
>
> [1] = 3; // SyntaxError
> x = ({foo: 1} = 3); // SyntaxError
>
> Bug in Firefox? Or subtlety of the spec that's gone over my head? :)
>

Destructuring (or, regarding JS -- "Non-strict pattern matching").

[a] = [3];

a; // 3

{a: b} = {a: 3, x: 4};

b; // 3

{a: c} = {};

c; // undefined

[x, y] = {not_an_array: 42}; // OK

[x, [y, z]] = {nor_here: 99}; // TypeError

https://mail.mozilla.org/pipermail/es-discuss/2010-July/011617.html

> Best regards,
>
> Michael
>



More information about the es-discuss mailing list