The following small series will bring you an article on object-oriented deep copy and shallow copy in JavaScript. I think this is quite good. Now I will share it with you and give you a reference. Let's take a look at the basic concepts that need to be understood before deep copy and shallow copy. The types of variables stored in the memory are divided into value type and reference type.
1. storage features of Value Type assignment. Copy all the data in the variable and store it to the new variable.
For example: var num = 123; var num1 = num;
The number stored in the variable is 123. Then copy the data, that is, copy 123. there are two arrays in the memory, and the copy data is assigned to num2, which features two data copies in the memory. this can be understood as a light copy.
2. assign values to the reference type.
Var o = {name: 'zhangsan '};
Var obj = o;
The value assignment is to copy the data stored in variable o and assign the value to obj. The memory contains 1 point of data. The name Attribute Modified using obj will affect the name in o.
If all the referenced structures of the data are copied in one copy, the data is copied independently in the memory;
If only the attributes of the current object are copied, and the attribute is of the reference type, it is a shortest copy;
Copy: Copy object data;
When discussing deep copy and shallow copy, make sure that the attributes of the object are also of the reference type.
In the above discussion, the object-oriented deep copy and shallow copy in JavaScript are all the content shared by the editor. I hope to give you a reference and support for PHP.
For more information about object-oriented deep copy and shortest copy in JavaScript, refer to PHP!