Problems with destructuring assignment and copying objects

Destructuring assignment is not copying new objects, but pointing to the same memory address

obj1 is an object, the object belongs to the reference value, obj2=obj1, it points to the memory address of the obj1 object together, so modify obj1.count=5, obj2 will also be modified. Object.assign() is to copy an object. If the source value is a reference to an object, it will only copy its reference value, so the count of obj3: 1;. JSON.parse(JSON.stringify(obj1)) is copying obj1, so copying obj1 is count: 5

 

Guess you like

Origin blog.csdn.net/ZHUzhuzhu08/article/details/121964308