An array destructing specification choice
Allen Wirfs-Brock
allen at wirfs-brock.com
Sat Nov 5 09:38:32 PDT 2011
In a similar vain, what is the value of r in:
let [z,y,...r] = {0:0, 1:1, 2:2, length: 3, 3:3,4:4};
should it be [2] or [2,3,4] (and if the latter how is that determined)?
It seems to me that [2] is the right answer, and if that is the cause, consistency requires that for the first problem z gets the value undefined.
Allen
On Nov 5, 2011, at 9:28 AM, Allen Wirfs-Brock wrote:
> In the following declaration, what should be the value of z?
>
> let [z,y,z] = {0:0, 1:1, length: 2, 2:2};
>
> should it be be 2 or undefined
>
> undefined might be reasonable because it is an array pattern, and the source object is only has two "array-like" elements
> 2 might be reasonable because the source object actually has a property named "2"
>
> Which alternative will be least surprising to JS programmers?
>
> Allen
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
More information about the es-discuss
mailing list