Thursday, 23 January 2020

Deep clone class instance JavaScript

I'm trying to figure out a way to deep clone a JS class instance while preserving all the prototypes down the chain.

I've seen how to deep clone and object:

JSON.parse(JSON.stringify(instance))

And I have seen how to make a shallow copy of a class instance:

Object.assign( Object.create( Object.getPrototypeOf(instance) ), instance)

But my question is, is there a way to deep clone an instance of a class?



from Deep clone class instance JavaScript

No comments:

Post a Comment