This is a creative idea. I'd rather see it in the language than not. But
still half a loaf.

Minor nit: I don't see how this is a "simplification in object
destructuring". It has nothing to do with destructuring, right?

I assume that this would work as expected?

```
{SANDWICHES[mySandwichName]}
```

to produce

```
{[mySandwichName]: SANDWICHES[mySandwichName]}
```

It's a bit sad that I don't see how to get to renaming and defaults with
this syntax.

Bob


On Thu, Sep 22, 2016 at 9:40 PM, Bergi <a.d.be...@web.de> wrote:

> 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
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to