davidmarkclements / rfdc

Really Fast Deep Clone
MIT License
635 stars 24 forks source link

cloning classes #25

Closed mrjjwright closed 3 years ago

mrjjwright commented 3 years ago

I used this library to clone a class hierarchy and everything works perfectly except the Class prototypes are not set properly. Is there any direction you can give me for cloning objects made with classes.

mrjjwright commented 3 years ago

Do I just do the following? This seems to work

class Model
{
  constructor(obj){
    Object.assign(this, obj)
  }
}

let obj = clone(anotherModel)

let m = new Model(obj) // look mom, a cloned Model