An array destructing specification choice
Allen Wirfs-Brock
allen at wirfs-brock.com
Mon Nov 7 08:53:43 PST 2011
On Nov 7, 2011, at 3:50 AM, Till Schneidereit wrote:
>> I.e., I think the most easily comprehensible behavior is to make array
>> destructuring treat the RHS as an Array.
>> It matches the common use-case (actual arrays), it is consistent (does
>> the same whether you use ... or not), and is easily explainable.
>
> I agree with the consistency argument. The reason I'm in favor of [no,
> no] is that otherwise
> [x,y,z] = {0:0, 1:1, 2:2}
> would result in
> x=undefined,y=undefined,z=undefined
>
> That doesn't seem desirable to me.
Yes, as I mentioned in another reply array [ ] access doesn't check length. But "slicing" operations including Array.prototype.slice and Function.prototype.apply (slices from 0 to length) all do use length.
That is way [no, yes] may actually be the most consistent approach.
Allen
More information about the es-discuss
mailing list