[proposal] Object.pick
T.J. Crowder
tj.crowder at farsightsoftware.com
Thu Jul 26 07:14:29 UTC 2018
On Wed, Jul 25, 2018 at 10:45 PM, Mikkel Davis
<mikkeld at gmail.com> wrote:
> I've seen proposals for syntax additions that give functionality
> similar to lodash's "pick" utility. But I think it may be more
> appropriate to add it as an Object utility in the same vein of
What I don't like about it being a utility function is the need to create
an array of property names or similar. Syntax has its own issues, but I
like Bob's proposal: https://github.com/rtm/js-pick-notation
> The only other concise way to do this I can think of, using latest ES is
> `(({first, age}) => ({first, age}))(person)`, which is quite undesirable,
> for a variety of reasons.
Just FWIW, you can avoid the function there, at the expense of a couple
more in-scope identifiers:
```js
const {first, age} = person, result = {first, age};
```
or to avoid those stray identifiers:
```js
let result;
{
const {first, age} = person;
result = {first, age};
}
```
If/when `do` expressions:
```js
const result = do {
const {first, age} = person;
({first, age});
};
```
None of which is pretty either. :-)
-- T.J. Crowder
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180726/4dcfcabb/attachment.html>
More information about the es-discuss
mailing list