Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upWhy Object.assign can't implement deep copy? #1319
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
ljharb
Oct 3, 2018
Member
Object.assign is variadic, so there’s no place to accept a flag.
See https://github.com/tc39/ecma262/blob/master/CONTRIBUTING.md for how to suggest a feature the language, but a deep copy that isn’t a structured clone (for which generic algorithms don’t yet exist in the language) would be very fragile.
In practice, I’ve found when i need a deep copy, it’s a code smell, and i can achieve a better solution by rearchicitecting to not need one - but that’s just my personal experience.
|
Object.assign is variadic, so there’s no place to accept a flag. See https://github.com/tc39/ecma262/blob/master/CONTRIBUTING.md for how to suggest a feature the language, but a deep copy that isn’t a structured clone (for which generic algorithms don’t yet exist in the language) would be very fragile. In practice, I’ve found when i need a deep copy, it’s a code smell, and i can achieve a better solution by rearchicitecting to not need one - but that’s just my personal experience. |
godkun commentedOct 3, 2018
Why Object.assign can't implement deep copy, if you can add a flag parameter to achieve deep copy, it will be perfect!!