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:

   1. is able to mixin also not enumerable and Symbols
   2. performs some unrequired magic such rebinding getters and setters
   that should not happen or actually does not make sense to me

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?

In few words I don't see how having both could hurt anyone




On Tue, Apr 22, 2014 at 10:27 AM, Claude Pache <[email protected]>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
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to