destructuring: as patterns?

Brendan Eich brendan at
Wed Apr 18 08:56:34 PDT 2012

Herby Vojčík wrote:
> Maybe allowing
>   let {b, b:{x,y}} = obj;
> would be enough. It sort-of comforms to existing syntax as well as 
> semantics.

That looks like a mistake. ES5 strict mode and so 1JS wants duplicate 
property names in object literals to be errors, so I expect the same for 
duplicate property names in destructuring patterns. Claus's 'as' syntax 
avoids that problem and could even be shortened:

    let { b as {x,y} } = obj

to bind b, x, and y, instead of what was in the o.p.:

    let { b: b as {x,y} } = obj

DRY and EIBTI argue for 'as' and the shorter shorthand.


More information about the es-discuss mailing list