destructuring: as patterns?

Allen Wirfs-Brock allen at
Thu Apr 19 14:18:50 PDT 2012

On Apr 18, 2012, at 2:48 PM, Brendan Eich wrote:

> David Herman wrote:
>> *Please*, let's do this right.
> This says to me (what I originally expected) that duplicate property name at any ply in an object pattern should be an early error.
> Anyone disagree?

I got as far as being ready to type into the spec. the first line to implement this restriction.  Then my reservations flamed-up. 

If you think of a destructuring declaration as simply a way to provide the initial values to a set of declaration is isn't so clear that duplicate property names are bogus.  Consider:

//initialize some variable with default objects
let {
     unidentifedAdult: mom,
     unidetifiedAdult: dad, 
     unidentiedChild: brother,
     unidentifiedChild: sister
     } = peopleConstants;

why is this less desirable than:

//initialize some variable with default objects
let mon = peopleConstants.unidentifiedAdult,
      dad = peopleConstants.unidentifiedAdult,
      brother = peopleConstants.unidentifiedChild,
      sister = peopleConstants.unidentifiedChild;

The former style is less familiar, but is it really "bad" enough to disallow at the language level?

Disallowing duplicate property names may make sense if you think about destructuring in ES declarations as  pattern matching (which it really isn't) or a means to break a composite into its constituent parts. But duplicate properties as initializers for a set of variables seem quite reasonable. 


More information about the es-discuss mailing list