Object.mixin rather than Object.getOwnPropertyDescriptors

Claude Pache claude.pache at gmail.com
Tue Apr 22 10:27:31 PDT 2014


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


More information about the es-discuss mailing list