guest271314 (2019-05-26T19:28:16.000Z)
In this case you can utilize a single step by setting a default value for
```otherData```

```let {firstName, lastName, otherData = "otherData"} = user.profile;```


On Sun, May 26, 2019 at 2:56 PM Григорий Карелин <grundiss at gmail.com> wrote:

> Yep, in the same way as destructuring would work
>
> вс, 26 мая 2019 г. в 17:52, guest271314 <guest271314 at gmail.com>:
>
>> If not found in source ```firstName``` and/or ```lastName``` would be
>> assigned the value ```undefined```?
>>
>> On Sun, May 26, 2019 at 1:40 PM Григорий Карелин <grundiss at gmail.com>
>> wrote:
>>
>>> Wouldn't it be nice to have syntax like this:
>>> const obj = { {firstName, lastName from user.profile}, otherData: 'other
>>> data'  };
>>> as a syntactic sugar for
>>> const obj = {firstName: user.profile.firstName, lastName:
>>> user.profile.lastName, otherData: 'other data'};
>>>
>>> Of cause at the moment we can write it in two steps:
>>> const {fistName, lastName} = userProfile;
>>> const obj = {firstName, lastName, otherData: 'other data'}
>>>
>>> But why use extra variables?
>>>
>>> Motivating example is lodash's .pick() method:
>>> https://lodash.com/docs/#pick
>>> _______________________________________________
>>> 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/20190526/4717bfb2/attachment.html>
guest271314 at gmail.com (2019-05-26T23:15:29.650Z)
To create individual variables and an object on the same line you can set the default value of ```obj``` to previously destructured values within target

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

The proposed syntax would eliminate duplicate code in the described context.

guest271314 at gmail.com (2019-05-26T23:15:03.424Z)
To create individual variables and an object on the same line you can set the default value of ```obj``` to previously destructured values within target

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

The proposed syntax would eliminate duplicate code.

guest271314 at gmail.com (2019-05-26T23:02:43.934Z)
To create individual variables and an object on the same line you can set the default value of ```obj``` to previously destructured values within target

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

guest271314 at gmail.com (2019-05-26T22:43:04.658Z)
To create individual variables and an object on the same line you can set the default value of ```obj``` to previously destructured values within target

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

guest271314 at gmail.com (2019-05-26T21:32:33.405Z)
To create individual variables and an object on the same line you can set the default value of ```obj``` to previously destructured values within target

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

alternatively

```// otherData` is not a property of `user.profile` and `otherData` will be set as property of `obj` ```

```let obj = {otherData: "other data"};```

```([{firstName:obj.firstName, lastName:obj.lastName}, {firstName, lastName, otherData}] = [user.profile, obj]);```

guest271314 at gmail.com (2019-05-26T21:30:31.582Z)
To create individual variables and an object on the same line you can set the default value of ```obj``` to previously destructured values within target

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

alternatively

```
// otherData` is not a property of `user.profile` and `otherData` will be set as property of `obj`
let obj = {otherData: "other data"};
([{firstName:obj.firstName, lastName:obj.lastName}, {firstName, lastName, otherData}] = [user.profile, obj]);
```

guest271314 at gmail.com (2019-05-26T21:08:13.723Z)
To create individual variables and an object on the same line you can set the default value of ```obj``` to previously destructured values within target

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

guest271314 at gmail.com (2019-05-26T21:04:29.929Z)
To create individual variables and an object on the same line you can create a function which returns an array or use an array literal with second index set to ```undefined``` where default value of ```obj``` will be populated by previously destructured values within target

```let [{firstName, lastName, otherData = "other data"}, obj = {firstName, lastName, otherData}] = [user.profile,];```

guest271314 at gmail.com (2019-05-26T21:02:52.803Z)

To create individual variables and an object create a function which returns an array or use an array literal with second index set to ```undefined``` where default value of ```obj``` will be populated by previously destructured values 

```let [{firstName, lastName, otherData = "other data"}, obj = {firstName, lastName, otherData}] = [user.profile,];```

guest271314 at gmail.com (2019-05-26T21:02:20.399Z)
In this case you can utilize a single step by setting a default value for
```otherData```

```let {firstName, lastName, otherData = "otherData"} = user.profile;```

To create individual variables and an object create a function which returns an array or use an array literal with second index set to ```undefined``` where default value of ```obj``` will be populated by previously destructured values 

```
let user = {profile: {firstName: "z"}};
let [{firstName, lastName, otherData = "other data"}, obj = {firstName, lastName, otherData}] = [user.profile,];
```

guest271314 at gmail.com (2019-05-26T21:01:42.392Z)
In this case you can utilize a single step by setting a default value for
```otherData```

```let {firstName, lastName, otherData = "otherData"} = user.profile;```

To create individual variables and an object create a function which returns an array or use an array literal with second index set to ```undefined``` where default value of ```obj``` will be populated by previously destructured values 

```
let user = {profile:{firstName:"z"}};
let [{firstName, lastName, otherData = "other data"}, obj = {firstName, lastName, otherData}] = [user.profile,];
```

guest271314 at gmail.com (2019-05-26T21:00:01.888Z)
In this case you can utilize a single step by setting a default value for
```otherData```

```let {firstName, lastName, otherData = "otherData"} = user.profile;```

To create individual variables and an object create a function which returns an array or use an array literal with second index set to ```undefined``` where ```obj``` will be populated by previously destructured values

```
let user = {profile:{firstName:"z"}};
let [{firstName, lastName, otherData = "other data"}, obj = {firstName, lastName, otherData}] = [user.profile,];
```

guest271314 at gmail.com (2019-05-26T20:59:29.871Z)
In this case you can utilize a single step by setting a default value for
```otherData```

```let {firstName, lastName, otherData = "otherData"} = user.profile;```

To create individual variables and an object create a function which returns an array or use an array literal with second index set to ```undefined``` where ```obj``` will be populated by previously destructured values

```
let user = {profile:{firstName:"z"}};
let [{firstName, lastName, otherData = "other data"}, obj = {firstName, lastName, otherData}] = [user.profile, void 0];
```

guest271314 at gmail.com (2019-05-26T20:56:08.279Z)
In this case you can utilize a single step by setting a default value for
```otherData```

```let {firstName, lastName, otherData = "otherData"} = user.profile;```

To create individual variables and an object create a function which returns an array with second index set to ```undefined` where ```obj``` will be populated by previously destructured values

```
let user = {profile:{firstName:"z"}};
let from = (o, ...props) => [Object.assign({}, props.map(prop => ({[prop]:o[prop]}))), void 0];
let [{firstName, lastName, otherData = "other data"}, obj = {firstName, lastName, otherData}] = from(user.profile, "lastName", "firstName");
```

guest271314 at gmail.com (2019-05-26T20:54:21.385Z)
In this case you can utilize a single step by setting a default value for
```otherData```

```let {firstName, lastName, otherData = "otherData"} = user.profile;```

To create individual variables and an object

```
let user = {profile:{firstName:"z"}};
let from = (o, ...props) => [Object.assign({}, props.map(prop => ({[prop]:o[prop]}))), void 0];
let [{firstName, lastName, otherData = "other data"}, obj = {firstName, lastName, otherData}] = from(user.profile, "lastName", "firstName");
```