❗️Object.assign copies with getter/setter
Last updated
Was this helpful?
Last updated
Was this helpful?
Was this helpful?
⭐ Object.assign()
copies with "get/set" operations, so if:
source object has a getter method, or
target object has a setter method
⭐ they will be invoked❗ during the assignment, not copied❗.
如果沒正確理解這個「複製過程」,可能會產生下列問題:
// the "source" object
const source = {
// ⭐ function copied ✅
max() {
console.log(this === source);
return 3;
},