Question ... perhaps a proposal: extract from object to object

T.J. Crowder tj.crowder at farsightsoftware.com
Fri Mar 17 12:46:57 UTC 2017


Important to remember that every change to syntax rattles a *bunch* of
parsing cages.

BTW, "pick" is exactly what Underscore calls this function:
http://underscorejs.org/#pick

> `_.pick(object, *keys) `

> Return a copy of the object, filtered to only have values for the
> whitelisted keys (or array of valid keys). Alternatively accepts
> a predicate indicating which keys to pick.
>
> ```js
> _.pick({name: 'moe', age: 50, userid: 'moe1'}, 'name', 'age');
> ```
> => `{name: 'moe', age: 50}`
>
> ```js
> _.pick({name: 'moe', age: 50, userid: 'moe1'}, function(value, key,
object) {
>  return _.isNumber(value);
> });
> ```
> => `{age: 50}`

I'd be more enthusiastic about `Object.pick` or similar, accepting an
iterable of whitelisted keys or a predicate function.

-- T.J. Crowder


On Fri, Mar 17, 2017 at 12:04 PM, Felipe Nascimento de Moura <
felipenmoura at gmail.com> wrote:

> Hi.
> Interesting to know that it has already been discussed.
>
> I know we could create a function to do similar things, but I think the
> language itself has evolved so well, this is a use case it could fit
> somehow.
>
> I think there could be different approaches for that, like
>
> Object.pick([ 'a', 'c' ], { a: 1, b: 2, c: 3 })
>
> or
>
> let x = {a, c}{ a: 1, b: 2, c: 3 }
>
> or
>
> let {a, c} as x = { a: 1, b: 2, c: 3 }
>
> or
>
>
> let x = { a: 1, b: 2, c: 3 }{a, c}
>
> or
>
> let x = { a: 1, b: 2, c: 3 }['a', 'c']
>
> Would you consider any of those as an interesting option?
>
> thanks.
>
>
>
> On Fri, Mar 17, 2017 at 7:25 AM, peter miller <fuchsia.groan at virgin.net>
> wrote:
>
>> Hi,
>>
>> There seems to be little appetite for taking it up, in spite of it being
>>> (IMHO) a very common use case.
>>>
>>
>> I'll second it being common in my code. My personal highlights would be
>> assigning to this:
>>
>> ```
>> this.{x,y,z} = a;
>> ```
>>
>> and combining it with property spreading:
>>
>> ```
>> const result = { a, b, ...x.{ y, z }, ...p.{ q, r } };
>> ```
>>
>> Peter
>>
>> --
>> "There were drawings, and sheets of paper with writing on them, and it
>> seemed that they were the sustenance of life, that here were the warlocks,
>> almost the vehicles of destruction of man's life, but at the same time the
>> very reason for his living." --- Maeve Gilmore/Titus Awakes.
>>
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>
>
>
> --
> [ ]s
>
> *--*
>
> *Felipe N. Moura*
> Web Developer, Google Developer Expert
> <https://developers.google.com/experts/people/felipe-moura>, Founder of
> BrazilJS <https://braziljs.org/> and Nasc <http://nasc.io/>.
>
> Website:  http://felipenmoura.com / http://nasc.io/
> Twitter:    @felipenmoura <http://twitter.com/felipenmoura>
> Facebook: http://fb.com/felipenmoura
> LinkedIn: http://goo.gl/qGmq
> ---------------------------------
> *Changing  the  world*  is the least I expect from  myself!
>
> _______________________________________________
> 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/20170317/81eb88ec/attachment-0001.html>


More information about the es-discuss mailing list