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

Felipe Nascimento de Moura felipenmoura at gmail.com
Fri Mar 17 13:08:17 UTC 2017


Indeed...I had got it wrong too!

We don't want someObj.map but Object.map ... and it is not supposed to be a
problem!

On Fri, Mar 17, 2017 at 10:03 AM, T.J. Crowder <
tj.crowder at farsightsoftware.com> wrote:

> > Indeed, Object.pick would be very promising, but it could indeed break
> some codes!
>
> Adding to *`Object`* (the function) is fine (usually, a survey would be
> needed). For instance, `Object.values` was added in ES2017. It's adding to
> *`Object.prototype`* that's impossible. Important distinction.
>
> -- T.J. Crowder
>
>
>
> *Farsight Software Ltd | 20-22 Wenlock Road, London N1 7GU | Company
> #8393428 tj.crowder at farsightsoftware.com <tj.crowder at farsightsoftware.com>
> | Direct: +44 (0)20 3627 4231 <+44%2020%203627%204231> | Mobile: +44
> (0)7717 842 414 <+44%207717%20842414>*
> If you've received this message in error, please let us know by forwarding
> it to info at farsightsoftware.com and then delete it from your system.
> Please don't copy it or disclose its contents to anyone. Separately, note
> that email sent over the internet without a digital signature may be
> modified en route.
>
> On Fri, Mar 17, 2017 at 12:53 PM, Felipe Nascimento de Moura <
> felipenmoura at gmail.com> wrote:
>
>> Well...this is a major problem, then!
>> Indeed, Object.pick would be very promising, but it could indeed break
>> some codes!
>>
>> On Fri, Mar 17, 2017 at 9:48 AM, Michał Wadas <michalwadas at gmail.com>
>> wrote:
>>
>>> It's impossible to add new methods on Object.prototype because it would
>>> be web-breaking - I have seen code that test for typeof arr.map ===
>>> 'function'
>>>
>>> On Set topic, I have written basic proposal for this
>>> <https://github.com/Ginden/set-methods>, but it was ignored so I didn't
>>> write formal spec.
>>>
>>> On 17/03/17 13:36, James Treworgy wrote:
>>>
>>> I think a good solution that doesn't require new syntax would be
>>> map/filter methods on the Object prototype that return a new object, e.g.
>>>
>>> let subset = { a:1, b:2, c:3 }.filter(([key])=>['b'].includes(key))
>>> // subset = { b: 2 }
>>>
>>> let subset = { 1:1, b:2, c:3 }.map(([key, value])=>[key, value * 2])
>>> // subset = { a:2, b:4. c:6 }
>>>
>>> Actually I'd like this to be available on Map too. I've always thought
>>> it was interesting that the Map and Set objects do not natively include
>>> map/filter operations -- or maybe even most of the Array prototype methods
>>> as applicable. And for Sets, basic set operations like
>>> except/distinct/union.
>>>
>>> But a Javascript object is just a Map, really, or I guess one could say
>>> that a Map is just an object with a few enhancements. It's surprising that
>>> there is no native operation built in to directly convert between Maps and
>>> objects given their conceptual similarity. In either case though it would
>>> be nice to be able to apply standard processing rules that one applies to
>>> Maps conceptually to an Object (and a Map) natively, like filter and map.
>>>
>>>
>>>
>>> On Fri, Mar 17, 2017 at 8:04 AM, 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
>>>>
>>>>
>>>
>>>
>>> _______________________________________________
>>> es-discuss mailing listes-discuss at mozilla.orghttps://mail.mozilla.org/listinfo/es-discuss
>>>
>>>
>>>
>>> _______________________________________________
>>> 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
>>
>>
>


-- 
[ ]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!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170317/353e411d/attachment-0001.html>


More information about the es-discuss mailing list