Extend Object Dereferencing

T.J. Crowder tj.crowder at farsightsoftware.com
Wed Oct 25 12:09:51 UTC 2017


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:

```js
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20171025/0e2618d5/attachment.html>


More information about the es-discuss mailing list