Le 22 avr. 2014 à 21:05, Andrea Giammarchi <andrea.giammar...@gmail.com> a 
écrit :

> IMO every time you use `getOwnPropertyDescriptor` over a 
> `getOwnPropertyNames` you are asking for a `getOwnPropertyDescriptors` 
> implementation, that's the use case.

And in these cases, again, are the descriptors used for something else than 
applying them immediately to another object? (This is a real question, for 
personally I barely use `getOwnPropertyNames` for other purpose than debugging.)

> 
> Twisting your question, do you have any use case for `getOwnPropertyNames` 
> that won't require later on `getOwnPropertyDescriptor` ?

Maybe, but `Object.getOwnPropertyNames` and `Object.getOwnPropertyDescriptor` 
(in ES5) are fundamental methods that cannot be decomposed into other methods, 
and on which libraries can build more complex functionalities. (Not sure about 
the `getOwnProperty{Names,Symbol}` dichotomy of ES6, but that's another 
question.) On the other hand `Object.getOwnPropertyDescriptors` and 
`Object.mixin` are complex methods.

—Claude

> 
> 
> On Tue, Apr 22, 2014 at 11:59 AM, Claude Pache <claude.pa...@gmail.com> wrote:
> 
> Le 22 avr. 2014 à 19:58, Andrea Giammarchi <andrea.giammar...@gmail.com> a 
> écrit :
> 
> > while I think that
> > Object.create(
> >
> >
> > Object.getPrototypeOf(originalObject),
> >
> >
> > Object.getOwnPropertyDescriptors(originalObject)
> > )
> > looks semantically better than
> > Object.mixin(
> >
> >
> > Object.create(Object.getPrototypeOf(originalObject)),
> >
> >   originalObject
> >
> > )
> > I also think that Object.mixin could be used for similar cases but I am not 
> > sure if:
> >       • is able to mixin also not enumerable and Symbols
> 
> When it was still in the ES6 draft, `Object.mixin` *did* copy all own 
> properties.
> 
> >       • performs some unrequired magic such rebinding getters and setters 
> > that should not happen or actually does not make sense to me
> 
> My feeling is that in most cases where that magic is not required, it is also 
> not very important. Or there could be an option for enabling/disabling that 
> functionality, for that would seem better to me than two wildly different 
> ways for getting almost the same result.
> 
> > The reason such long method name has been proposed was for symmetry with 
> > defineProperties and as meaningful plural version that should not exclude 
> > Object.mixin
> >
> > Long story short, when mixin is needed, use mixin, otherwise when all 
> > descriptors are needed, use getOwnPropertyDescriptors?
> 
> Do you have cases where getting all descriptors is used for something else 
> than setting them immediately to another object? My point is that I don't see 
> the added value of `Object.getOwnPropertyDescriptiors` once you have a 
> correctly designed `Object.mixin`-like method.
> 
> —Claude
> 
> 
> >
> > In few words I don't see how having both could hurt anyone
> >
> >
> >
> >
> > On Tue, Apr 22, 2014 at 10:27 AM, Claude Pache <claude.pa...@gmail.com> 
> > wrote:
> > Hi,
> >
> > There has been request to add `Object.getOwnPropertyDescriptors` (plural) 
> > to the standard. Reviewing use cases presented in thread [1] or in older 
> > thread [2], it seems to me that all of them boil down to copy all own 
> > properties of one object to another, e.g.,
> >
> >     Object.defineProperties(target, 
> > Object.getOwnPropertyDescriptors(source))
> >     Object.create(proto, Object.getOwnPropertyDescriptors(source))
> >     // etc.
> >
> > However, this is exactly what `Object.mixin` (deferred from ES6) was 
> > designed for:
> >
> >     Object.mixin(target, source)
> >     Object.mixin(Object.create(proto), source)
> >     // etc.
> >
> > Besides being shorter to write, `Object.mixin` has the advantages of (1) 
> > not creating an intermediate object; (2) taking care of some subtleties, 
> > like rebinding `super` for methods, getters and setters if needed.
> >
> > Therefore, I think that `Object.mixin` is a better function to have than 
> > `Object.getOwnPropertyDescriptors`.
> >
> > —Claude
> >
> >
> > [1] http://esdiscuss.org/topic/object-getownpropertydescriptors-o-plural
> > [2] http://esdiscuss.org/topic/object-getownpropertydescriptor
> > _______________________________________________
> > es-discuss mailing list
> > es-discuss@mozilla.org
> > https://mail.mozilla.org/listinfo/es-discuss
> >
> 
> 

_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to