To clone a JavaScript ES6 class instance, we use a few object methods.
For instance, we write
const clone = Object.assign(Object.create(Object.getPrototypeOf(orig)), orig);
to get the prototype of the orig
object with Object.getPrototypeOf
.
Then we create a new object from the prototype with Object.create
.
Then we call Object.assign
to make a copy of the object we created and return it.