Object.assign and exceptions (was: Object.assign and __proto__ property)

Erik Arvidsson erik.arvidsson at gmail.com
Tue Oct 22 07:00:18 PDT 2013


The spec for Object.assign,
http://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.assign,
seems to have some issues.

*gotAllNames* is never read.

What is the intention regarding exceptions? Is the intention to continue
assigning properties after an exception is thrown. Why is that the desired
behavior?

On Tue, Oct 22, 2013 at 6:41 AM, André Bargull <andre.bargull at udo.edu>
wrote:
...
> A more conformant implementation should be this one:
>
> function assign(target, source) {
>   function ToObject(o) {
>     if (o == null) {
>       throw new TypeError();
>     }
>     return Object(o);
>   }
>   var to = ToObject(target);
>   var from = ToObject(source);
>   var keys = $getOwnPropertyNames(from);
>   var pendingException = null;
>   for (var i = 0, length = keys.length; i < length; ++i) {
>     var nextKey = keys[i];
>     try {
>       var desc = $getOwnPropertyDescriptor(from, nextKey);
>       if (desc !== undefined && desc.enumerable) {
>         to[nextKey] = from[nextKey];
>       }
>     } catch (e) {
>       if (pendingException !== null) {
>         pendingException = e;
>       }
>     }
>   }
>   if (pendingException !== null) {
>     throw pendingException;
>   }
>   return to;
> }
>
>
> - André
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss


-- 
erik
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20131022/b4de03bf/attachment.html>


More information about the es-discuss mailing list