Extend Object Dereferencing

# Sebastian Malton (7 years ago)

An HTML attachment was scrubbed... URL: esdiscuss/attachments/20171024/e2ca110e/attachment

# Sebastian Malton (7 years ago)

An HTML attachment was scrubbed... URL: esdiscuss/attachments/20171024/1c474eb4/attachment

# Bob Myers (7 years ago)

Don't you just mean the following:

const {abc, xyz, qnc: {awj}} = obj;
# Sebastian Malton (7 years ago)

An HTML attachment was scrubbed... URL: esdiscuss/attachments/20171024/940ef4da/attachment

# Bob Myers (7 years ago)

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

# Sebastian Malton (7 years ago)

An HTML attachment was scrubbed... URL: esdiscuss/attachments/20171024/00511228/attachment-0001

# T.J. Crowder (7 years ago)

On Tue, Oct 24, 2017 at 7:51 PM, Sebastian Malton <sebastian at malton.name> wrote:

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.

You don't have to do it again, you can nest patterns as deeply as you like. In this case:

const {abc, xyz, qnc: {awj}} = obj;
```j

E.g.: http://jsfiddle.net/yyud2gvg/

```js
const obj = {
    abc: 1,
    xyz: 2,
    qnc: {
        awj: 3
    }
};
const {abc, xyz, qnc: {awj}} = obj;
console.log(abc, xyz, awj); // 1, 2, 3
```js

-- T.J. Crowder
# Sebastian Malton (7 years ago)

An HTML attachment was scrubbed... URL: esdiscuss/attachments/20171025/1f319185/attachment-0001

# T.J. Crowder (7 years ago)

On Wed, Oct 25, 2017 at 1:15 PM, Sebastian Malton <sebastian at malton.name> wrote:

I didn't mean that part when I said multiple levels. I meant the following

const abc = { { bcd, cde, efg: {qnc} } = obj};

I was responding to your initial assertion in your first message, which didn't show that form. It just said

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.

I was pointing out how you can do that without having to "do it again."

Perhaps you could clarify what you're actually proposing. Your first message talked about individual variables for the parts of obj; subsequently you seemed to be talking about creating a new object (combining object initializers with destructuring)...?

-- T.J. Crowder