Extend Object Dereferencing

Bob Myers rtm at gol.com
Tue Oct 24 19:25:52 UTC 2017


If your intent is to say

```
const a = {b: e.b, c: e.c, d: e.d};
```

then the reception to such functionality (often referred to as "picking")
on this list has been decidedly lukewarm, although I remain mystified why,
since IMHO it is a common use case and syntactically straightforward. FWIW
the currently proposed syntax is

```
const a = { {b, c, d} = e };
```

which allows combining properties from more than one object, as in

```
const a = { {b, c, d} = e, {g, h, i} = k };
```

which is equivalent to

```
const a = {b: e.b, c: e.c, d: e.d, g: k.g, h: k.h, i: k.i};
```

Bob

On Wed, Oct 25, 2017 at 12:39 AM, Sebastian Malton <sebastian at malton.name>
wrote:

> I guess I do except for the second part
>
> ```
> const a = {b, c, d} = e;
> ```
>
> *From:* rtm at gol.com
> *Sent:* October 24, 2017 3:07 PM
> *To:* sebastian at malton.name
> *Cc:* es-discuss at mozilla.org
> *Subject:* Re: Extend Object Dereferencing
>
> Don't you just mean the following:
>
> ```
> const {abc, xyz, qnc: {awj}} = obj;
> ```
>
> On Wed, Oct 25, 2017 at 12:22 AM, Sebastian Malton <sebastian at malton.name>
> wrote:
>
>> This could also be extended to help with cleansing objects.
>>
>> const abc = {cde, def, efg} = obj;
>>
>> Would create an object abc with only those three fields in it.
>>
>> *From:* sebastian at malton.name
>> *Sent:* October 24, 2017 2:51 PM
>> *To:* es-discuss at mozilla.org
>> *Subject:* Extend Object Dereferencing
>>
>> Currently you can do the following
>>
>> const {abc, xyz, qnc} = obj;
>>
>> However if you want to go more than one level deep then you have to do it
>> again for each level.
>>
>> I therefore propose the ability to do the following
>>
>> const {abc, xyz, qnc.awj} = obj;
>>
>> And this would create the variables 'abc'', 'xyz', 'awj' with the values
>> from obj. If qnc is not present then an undefined dereference exception
>> would be thrown.
>>
>> This could also be extended with the proposed '?.' notation to go even
>> deeper safely.
>>
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20171025/3bc922d5/attachment.html>


More information about the es-discuss mailing list