Object.mixin rather than Object.getOwnPropertyDescriptors

Andrea Giammarchi andrea.giammarchi at gmail.com
Tue Apr 22 10:58:11 PDT 2014

while I think that


looks semantically better than


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

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 <claude.pache at 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 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/20140422/2debc2b0/attachment-0001.html>

More information about the es-discuss mailing list