Object.assign and __proto__ property

Andrea Giammarchi andrea.giammarchi at gmail.com
Sat Oct 19 10:57:29 PDT 2013


here again dunder keyword ^_^

As it is Object.assign does not bring any benefit over

```javascript

for(var key in source) {
  target[key] = source[key];
}

```

except former pattern can easily filter undesired properties such

```javascript

for(var key in source) {
  if (key != '__proto__') {
    target[key] = source[key];
  }
}

```

which is the new `hasOwnProperty` for ES5 era ...


I am not saying `Object.assign` should skip such property, 'cause when we
deal with dictionaries everything should be considered valid, but I miss
any advantage on using such method if not a false feeling that's gonna be
safer 'cause implemented in core.

My 2 cents





On Sat, Oct 19, 2013 at 9:57 AM, Allen Wirfs-Brock <allen at wirfs-brock.com>wrote:

>
> On Oct 19, 2013, at 7:55 AM, Rick Waldron wrote:
>
>
>
> On Sat, Oct 19, 2013 at 10:25 AM, teramako <teramako at gmail.com> wrote:
>
>> Hi
>>
>> I believe Object.assign never update the target's [[prototype]]. But
>> current rev19 spec is using Put. So I'm afraid of following case will
>> update the [[prototype]].
>>
>> var soruce = {};
>> Object.defineProperty(source, "__proto__", {
>>     value: { a: "A", b: "B" },
>>     enumerable: true
>> });
>> var target = {};
>> Object.assign(target, source);
>>
>> Is this expected result ? and is there a plan to change to
>> DefinePropertyOrThrow from Put ?
>>
>
> Object.assign is essentially a "batch property assignment with Put"; I
> believe what you're describing above is Object.mixin, which is "batch
> property definition with DefinePropertyOrThrow".
>
>
> Actually, this is a good point.  As currently specified Object.assign of
> with an own __proto__ property on the RHS object will trigger a
> [[SetPrototypeOf]] on the LHS object.  Is that what we want.  It is a
> direct fallout of specifying Object.assign as the equivalent of a sequence
> of property assignments from the RHS to the LHS.   "__proto__" could be
> special cased.  But should it?
>
> Object.mixin doesn't have this issue because, as Rick points out, it uses
> GetOwnProperty/DefineProperty instead of Get/Set.
>
> Anybody want to argue that Object.assign shouldn't trigger
> [[SetPrototypeOf]]?
>
> Allen
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20131019/0bd45369/attachment.html>


More information about the es-discuss mailing list