Destructuring an object into a new object (like Underscore pick but ESier)

Bergi a.d.bergi at web.de
Mon Feb 22 00:46:40 UTC 2016


Viktor Kronvall schrieb:
> What would this do?
> ```
> let newObj = {obj.a.b}
> ```
>
> `{a: {b: obj.a.b}}`
> or
> `{a: obj.a.b}`?
>
> Or should nested property access be disallowed?

Neither - `obj.a.b` is `(obj.a).b`, so it's equivalent to `let newObj = 
{b: obj.a.b}`.
The spec would basically be something like

| Let propKey be GetReferencedName(exprValue)

and otherwise [the 
same](http://www.ecma-international.org/ecma-262/6.0/#sec-object-initializer-runtime-semantics-propertydefinitionevaluation).


More information about the es-discuss mailing list