Object.define ==> Object.mixin??

John J Barton johnjbarton at johnjbarton.com
Wed Dec 12 09:50:55 PST 2012


On Wed, Dec 12, 2012 at 9:42 AM, Brandon Benvie
<brandon at brandonbenvie.com>wrote:

> Ah yes errors. It should probably have similar semantics to how
> defineProperties works now...attempting each property and holding errors
> until the end, no? Same for assign.


No, we want early errors and accurate line numbers.


>
> function mixin(target, source){
>   if (Type(target) !== 'Object') throw new TypeError ("target must be an
> object");
>

No, Object.keys() will report TypeError: Object.keys called on non-object


>   if (Type(source) !== 'Object') throw new TypeError("source must be an
> object");
>
>   var error;
>   Object.keys(source).forEach(function(key){ // or getOwnPropertyNames?
>     try {
>       Object.defineProperty(target, key,
> Object.getOwnPropertyDescriptor(source, key));
>     } catch (e) {
>       error || (error = e);
>     }
>   });
>
>   if (error) throw error;
>   return target;
> }
>

But most of all we want this feature to land and not just spin around here.

jjb
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121212/2944f48a/attachment.html>


More information about the es-discuss mailing list