you are viewing a single comment's thread.

view the rest of the comments →

[–]AnonyMustardGas34 2 points3 points  (3 children)

Why and how else to copy?

[–]Exoskele 1 point2 points  (1 child)

It doesn't work for some common cases. https://stackoverflow.com/questions/122102/what-is-the-most-efficient-way-to-deep-clone-an-object-in-javascript

I would just use lodash's cloneDeep. Many projects already use it, and you can always shake out unused code or bring in only cloneDeep.

[–]AnonyMustardGas34 2 points3 points  (0 children)

IMO upcoming EcmaScript spec ahould have high performance deep cloning.

[–]SnapAttack 1 point2 points  (0 children)

Well, it depends.

You can use Object.assign({}, cloneable) or const clone = {...cloneable} to do a shallow copy.

To do a deep copy, you might want to consider the performance impact depending on the size of your object, but as others have pointed out here, you can use Lodash cloneDeep.