I have found this problem with spread operator when cloning a class instance. The methods context remain with the original instance. Somebody knows how to fix it?
class Person {
constructor(name) {
this.name = name;
this.setName = name => {
this.name = name;
};
}
}
const a = new Person('John');
console.log(a.name); //John
const b = { ...a };
console.log(b.name); //John
b.setName('Paul');
console.log(b.name); //John
console.log(a.name); //Paul