agreed, and actually one of the best case I've seen in a while for Array#reduce.
Can I write this as it should be for those who'll read one day later on and making it also static ? "mixin" in Object || Object.defineProperty(Object, "mixin", { value: function mixin(target, source) { return Object.getOwnPropertyNames(source).reduce(function (target, name) { return Object.defineProperty( target, name, Object.getOwnPropertyDescriptor(source, name) ); }, target); } }); also thinking about try/catch to avoid mixin overwrite ... I believe it's OK if that throws an error but then it should throw regardless if the target object had already that property defined ? br On Wed, Dec 12, 2012 at 7:43 AM, Brandon Benvie <bran...@brandonbenvie.com>wrote: > Works well as an arrow function due to not needing to turn it into a block > body, although forEach and a comma would work too. > > Object.mixin = (target, source) => > Object.keys(source).reduce((target, key) => > Object.defineProperty(target, key, > Object.getOwnPropertyDescriptor(source, key)) > ), target); > > _______________________________________________ > 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