[proposal] Object.pick

Mikkel Davis mikkeld at gmail.com
Thu Jul 26 21:42:12 UTC 2018

Thank you, TJ. Those are some other interesting options. But undesirable,
like you say, least of which because they all require repetition like my
snippet in my original post. At least the array of properties avoids the
repetition. I agree it's not ideal because of the extra quote marks, but my
IDE is still able to follow the logic and point me to where the
property/method was included down the line. And really properties are just
strings. The quotes would be required anyway with a syntactic solution for
properties such as "thing-1", "2thing".

I would love to see a great syntactic solution like the one you mentioned,
but as we know it is far more involved to implement those and many do not
survive for a variety of reasons. Why not pursue both proposals? We have
Array.prototype.concat and array spread, Object.assign and object spread,
Boolean(val) and !!val. I realize not all of those are entirely
equivalent--my point is that I think there is value in pursing this
proposal separate from syntax.

P.S. I haven't used this mailing list before, so I'm not sure why my
previous response was all bold. I apologize if this one is, too. I'm just
responding via Gmail. No formatting in my response text that I can tell.

Mikkel R. Davis

On Thu, Jul 26, 2018 at 1:14 AM T.J. Crowder <
tj.crowder at farsightsoftware.com> wrote:

> 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/5ec7b19f/attachment.html>

More information about the es-discuss mailing list