You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.
Current implementation of the spread operator in browsers copy Symbol property when used.
What I see here is inconsistency.
On the one hand spread operator and Object.assign both do copy Symbol property.
On the other hand, Symbol property doesn't appear in for...in loop and completely ignored by JSON.stringify and JSON.parse.
Steps to reproduce the problem:
Define object on which Symbol will be used as property name (e.g. obj[Symbol("secret property")] = "secret value")
Using spread operator copy all properties to another object (e.g. const newObj = {...obj})
Spread operator should copy only own enumerable (which is not relevant to the property named using Symbol as it's not enumerable) properties from a provided object onto a new object.
(which is not relevant to the property named using Symbol as it's not enumerable)
That is not the case, Symbol properties may or may not be enumerable, just like any other property.
On the other hand, Symbol property doesn't appear in for...in loop and completely ignored by JSON.stringify and JSON.parse.
What is leading to your confusion is that for..in and JSON.stringify (and Object.keys and such) don't simply iterate own enumerable properties, it is explicitly specced to iterate and only process string-keyed properties of the given object.
Current implementation of the spread operator in browsers copy
Symbol
property when used.What I see here is inconsistency.
On the one hand spread operator and Object.assign both do copy
Symbol
property.On the other hand,
Symbol
property doesn't appear infor...in
loop and completely ignored byJSON.stringify
andJSON.parse
.Steps to reproduce the problem:
obj[Symbol("secret property")] = "secret value"
)const newObj = {...obj}
)Spread operator should copy only own enumerable (which is not relevant to the property named using Symbol as it's not enumerable) properties from a provided object onto a new object.
Checked in:
Chrome version: 63.0.3239.132
(Windows 7)
working example: https://goo.gl/SkHd3H
The text was updated successfully, but these errors were encountered: