An array destructing specification choice
Brendan Eich
brendan at mozilla.com
Sat Nov 5 19:02:45 PDT 2011
On Nov 5, 2011, at 5:52 PM, Allen Wirfs-Brock wrote:
> On Nov 5, 2011, at 2:34 PM, Brendan Eich wrote:
>
>> On Nov 5, 2011, at 11:27 AM, Allen Wirfs-Brock wrote:
>>
>>>> It should, as no length is assumed to mean "length === 0", IIUC, and
>>>> that seems so unintuitive to me that it sways my opinion towards not
>>>> imposing array-ness on the RHS.
>>>
>>> but that is exactly how it works everywhere else length is used in ES.
>>
>> Who says 'length' is used by an array destructuring pattern. That should not be assumed.
>
> just to clarify, everywhere else a range of "array" elements is used, the range is limited by the value of the "length" property. Regardless of where or not the object in question is a "real" array.
Ok, but perhaps we agree, since I've thrown in with Arv on getting 'length' for an array pattern directly containing a ... special form. But not for other array patterns!
>>> So you would be fine with the fact that
>>>
>>> var r = Array.prototype.slice.call(0:0, 1:1, length: 2, 2:2}, 0);
>>>
>>> produces [0,1]
>>>
>>> but
>>>
>>> var [...rx] = {0:0, 1:1, length: 2, 2:2};
>>>
>>> produces [0,1,2]
>>
>> Even if Till would not (and it's clear you would not be fine with this outcome ;-), we have a choice. We can make array destructuring patterns that do not use ... ignore any RHS 'length' property. We could even forbid this kind of "row capture" -- I'm not in favor.
>
>
> I was fine with it to, until ... came along. If ... uses length (and I think it probably should, as I touched on in another reply) then element access also should)
That "should" doesn't follow. It's a choice and the way you chose violates pay-for-what-you-take. Not something I want in my favored dining establishments. Salad buyer pays for steak? Hmph!
>> Row capture in object patterns requires enumeration of RHS properties. Have you worked on that case too?
>
>
> No, row capture was never accepted as part of the proposal.
Well, Arv added ... in array patterns under "issues" and I don't remember working through the ramifications -- indeed, here we are. Why rule out row capture? Arrays are "easier" because of 'length' but we enumerate object keys in many places in ES5 already. What's one more?
/be
More information about the es-discuss
mailing list