Object arithmetic--operator alternative to Object.assign

Edwin Reynoso eorroe at gmail.com
Tue Mar 24 23:09:12 UTC 2015


For different objects this is the only way I see possible with
destructuring. IMO it's a bit ugly and weird to read deep destructuring:

```
let x = { a: 1 };
let y = { b: 2 };
let { x: { a }, y: { b } } = { x, y };
```

But I'd prefer Bob Myers's way:

```
let x = { a: 1 };
let y = { b: 2 };
{x.a, y.b}
```

Now that would be for destructuring. But isn't the following shorthand
property assignment not destructuring:

```
var c = {x,y};

//so I'm thinking Bob wants the following:

var c = {x.a, b.y}; // {a: 1, b: 2}
```

On Tue, Mar 24, 2015 at 3:51 PM, Tab Atkins Jr. <jackalmage at gmail.com>
wrote:

> On Tue, Mar 24, 2015 at 9:44 AM, Bob Myers <rtm at gol.com> wrote:
> > Apologies if something like this has already been proposed.
> >
> > We have simplified object literal syntax:
> >
> > {a, b}
> >
> > However, I often find myself writing this:
> >
> > {a: x.a, b: y.b}
> >
> > Would it be possible to have a syntax such as
> >
> > {x.a, y.b}
> >
> > Where the property name is taken from the last segment of the property
> > reference, so that `x.a` becomes the value of property `a`?
>
> If you're taking both values from the *same* object, we have the syntax:
>
> {a, b} = x;
>
> This may or may not help you.
>
> ~TJ
> _______________________________________________
> 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/20150324/33701dac/attachment.html>


More information about the es-discuss mailing list