destructuring: as patterns?

Herby Vojčík herby at
Wed Apr 18 13:45:48 PDT 2012

Brendan Eich wrote:
> Allen Wirfs-Brock wrote:
>>> For array patterns we would need to allow property assignments in
>>> array literals:
>>> > > let [b, 0:{x,y}] = ...;
>>> > > This was proposed at one point, IIRC, but a while ago.
> Of course, one could destructure like so:
> let {0: b, 0: {x, y}} = ...;
>> It was also suggested that we allow iterators/generators to supply the
>> initialization values to array destructurings. This currently isn't in
>> the draft spec. and I think it would introduce some fairly significant
>> specification and practical complications (eg, rest bindings and
>> open-ended generators).
> Destructuring patterns should be static. I don't see a conflict if we
> stick to this rule, but given the ability to use an object pattern, I
> don't see a need for the array literal element label syntax either.

As was already pointed out, problems are not only _array_ 
destructurings, but more argument list destructrings, where if you want 
to destructure 0-th argument both as b and as {x,y}, you would need 
something like that, since you already are inside list, you cannot opt 
for object.

(but if it is not the problem, I'd gladly see at least the object 
double-destructure-same-field in ES6. It is not violating the "no double 
property names" of strict mode since the assignment goes the other way)

> /be


More information about the es-discuss mailing list