Proposal: syntactic sugar for extracting fields from objects

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Proposal: syntactic sugar for extracting fields from objects

Bob Myers
Similar proposals have been out there for years. For whatever reason, none have gotten traction.

Under one proposal, your scenario would be

```
const obj ={...user_profile.{firstName, lastName}, otherData: 'other data'};
```


Bob

---------- Forwarded message ----------
From: "Григорий Карелин" <[hidden email]>
To: [hidden email]
Cc: 
Bcc: 
Date: Sun, 26 May 2019 16:39:58 +0300
Subject: Proposal: syntactic sugar for extracting fields from objects
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
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss