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

2017-03-31 Thread peter miller
Hi Felipe, Object.pick([ 'a', 'c' ], { a: 1, b: 2, c: 3 }) I just dislike having identifiers in strings. And while I'm here, nobody's mentioned the prior art of slicing hashes in perl. For that reason, I call my function `slice()` (but that's probably a bad name for web compatibility).

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

2017-03-17 Thread Felipe Nascimento de Moura
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.crow...@farsightsoftware.com> wrote: > > Indeed, Object.pick would be very promising, but it could indeed break > some codes!

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

2017-03-17 Thread T.J. Crowder
> 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.

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

2017-03-17 Thread James Treworgy
> > I have seen code that test for typeof arr.map === 'function' Is the intent of this to test if something is an array? It seems that that code is fundamentally brittle (I mean, anyone can create anything with a "map" method). I see the point generally of being wary of extending Object -- but

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

2017-03-17 Thread Felipe Nascimento de Moura
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 wrote: > It's impossible to add new methods on Object.prototype because it would be > web-breaking - I

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

2017-03-17 Thread Felipe Nascimento de Moura
cool...I like this approach too! A little bit verbose, but looks to be more powerful for other operations we haven't event figured out yet. It would give developers a new set of possibilities and tools. I still think that a syntax similar to one of those I suggested would be very helpful, in

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

2017-03-17 Thread Michał Wadas
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 , but it was ignored so I didn't write formal spec.

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

2017-03-17 Thread T.J. Crowder
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

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

2017-03-17 Thread James Treworgy
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])

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

2017-03-17 Thread Felipe Nascimento de Moura
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' ],

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

2017-03-17 Thread peter miller
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 = {

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

2017-03-16 Thread Bob Myers
This has been discussed ad nauseum, in this thread and elsewhere. Some people call this "picking", or "deconstructing into objects". There seems to be little appetite for taking it up, in spite of it being (IMHO) a very

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

2017-03-16 Thread Felipe Nascimento de Moura
Hi. I am trying to get an object out of another object, with only a few of its properties. I know we can do this: let { a, c } = { a: 1, b: 2, c: 3 } In this case, we have a variable 'a' and a variable 'c'. What I want is { a: 1, c: 3} Is there a way to do it? Something like: let { a, c } as