An array destructing specification choice

Dmitry Soshnikov dmitry.soshnikov at gmail.com
Sat Nov 5 09:45:01 PDT 2011


On 05.11.2011 20:38, Allen Wirfs-Brock wrote:
> 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,

How so? If `...n` is the range slice operator, it should be [2, 3, 4], no?

Dmitry.
>   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
>>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss



More information about the es-discuss mailing list