On Mon, Oct 21, 2013 at 11:26 PM, Andrea Giammarchi <
[email protected]> wrote:

> As sanity/integrity check, `Object.assign` should be something like this
> to me ...
>
> ```javascript
>
> for (var property in source) {
>   if (Object.prototype.hasOwnProperty.call(source, key)) {
>     if (key in target) {
>       Object.defineProperty(
>         target, key,
>         Object.getOwnPropertyDescriptor(
>           source, key
>         )
>       );
>     } else {
>       target[key] = source[key];
>     }
>

This is exactly why there is Object.assign and Object.mixin (originally
called Object.define), because you can't make this semantic decision and
assume that it's what all code wants all the time.



>   }
> }
>
> ```
>

Traceur has:

function assign(target, source) {
  var props = $getOwnPropertyNames(source);
  var p, length = props.length;
  for (p = 0; p < length; p++) {
    target[props[p]] = source[props[p]];
  }
  return target;
}

Which is correct.





> If this is what every dev should do in order to have a meaningful version
> of current `Object.assign`,
>

But it's wrong.



> I agree with Rick that in core this could/would be properly optimized and
> made faster.
>

Thanks

Rick
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to