>
> ```
> let obj = {otherData: "other data"};
> ({firstName:obj.firstName, lastName:obj.lastName} = user.profile);
> ```
>

I don't understand this.


> Alternatively there are various approaches which can be used to get only
> specific properties from an abject and set those properties and values at a
> new object without using destructing assignment.
>
> Using object rest and ```reduce()```
>
> ```let obj = {otherData: "other data", ...["firstName",
> "lastName"].reduce((o, prop) => (o[prop] = user.profile[prop], o), {})};```
>
> `Object.assign()`, spread syntax and `map()`
>
> ```let obj = Object.assign({otherData: "other data"}, ...["firstName",
> "lastName"].map(prop => ({[prop]:user.profile[prop]})));```
>

As the words "syntactic sugar" in the subject of the thread make clear, the
OP is not merely looking for ways to assign one object's property into
another--there are many ways to do that. He's looking for a terser, moire
elegant way to do it, which hopefully would be moire semantic, less
bug-prone, more type-checkable (for typed variants of the language), more
reminiscent of existing syntax such as deconstruction, and potentially more
optimizable by engines.

Bob
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to