Extended dot notation (pick notation) proposal

Bergi a.d.bergi at web.de
Thu Sep 22 16:10:46 UTC 2016


Jonathan Bond-Caron wrote:
> On Tue Sep 20 03:38 PM, Bob Myers wrote:
>>
>> People in the real world continue to wonder why they can't
>> pick/destructure from objects into objects, instead of just variables.

Yeah, StackOverflow is hit pretty often with people asking how to do that.

> Seems like allowing to "dot" into another identifier could work:
> https://tc39.github.io/ecma262/#prod-CoverInitializedName
>
> CoverInitializedName[Yield]:
>   IdentifierReference[?Yield]  Initializer[+In, ?Yield]
>   IdentifierReference[?Yield]  . IdentifierName

I don't think that's the right grammar rule, but yes, I'd love to see this:

> const IDENTIFIER = 1;
> const sandwichesIWantToEat = { SANDWICHES.CHEESE_STEAK, SANDWICHES.SLOPPY_JOE, IDENTIFIER };
>
> Use the RHS identifier as the member/property name and resolve the "dot" expression to get the value.
>
> const sandwichesIWantToEatResult = { CHEESE_STEAK: SANDWICHES.CHEESE_STEAK, SLOPPY_JOE: SANDWICHES.SLOPPY_JOE, IDENTIFIER: IDENTIFIER };

This simplification in object destructuring and shorthand property 
intialisers should be easy to add to the language and rather simple to 
understand. There are no grammar ambiguities, and no completely new 
productions, but I believe it would help a great deal.
Yes, one would still have to repeat the name of the object to/from which 
the properties to assign/take, but that's usually rather short so it's 
not a large burden.

I could create a proposal repo, who would like to help?

kind regards,
  Bergi



More information about the es-discuss mailing list