クラスをコピーする


class Person {
    constructor(name) {
        this.name = name;
    }
}
const john = new Person('John');
const clone = Object.assign(Object.create(Object.getPrototypeOf(john)), john);
console.log(Object.getPrototypeOf(john));

john.name = 'John Doe';
console.log(clone); // 別オブジェクトなのでnameは'John'のままです
console.log(john);

prototypeが必要なく、単純に各プロパティをshallow copyしたオブジェクトが欲しいだけであればspread operatorを使用することもできます

const clone = {...john}