New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why Object.assign can't implement deep copy? #1319

Closed
godkun opened this Issue Oct 3, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@godkun

godkun commented Oct 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!!

@ljharb

This comment has been minimized.

Show comment
Hide comment
@ljharb

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.

Member

ljharb commented Oct 3, 2018

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.

@ljharb ljharb closed this Oct 3, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment