And the answer is:
Functions declared inside a class with the function keyword are added to the prototype of the object and are not copied with the spread operator {...}
.
Functions declared inside a class as arrow functions, are copied over with spread operator and are present on the object level.
In case you are using Redux, and classes inside the state, write your classes with the arrow functions.
class C {
doSomethingFunc() {
console.log("Name is name")
}
doSomethingVar= () => {
console.log("Last name is")
}
}
const originalInstance = new C();
const newInstance = {...originalInstance};
originalInstance.doSomethingFunc()
originalInstance.doSomethingVar()
newInstance.doSomethingVar()
newInstance.doSomethingFunc() // ERROR: prototypal functions are not copied with spread operator.