当前位置:网站首页>JS deep and shallow copy

JS deep and shallow copy

2022-06-12 20:35:00 Stand on the bridge and bake cold noodles

Shallow copy : If you want to copy the basic data type , Then shallow copy can be implemented . If it is data of reference type , A shallow copy simply implements a reference to a memory address , Modify the original data , Will affect the copied data .

Deep copy : Realize the copy of data and memory address , It is equivalent to reopening the space to store data and memory addresses .

How to realize deep copy :1. Passing objects through json.stringfy Convert to string , Assign to new variable , Then pass the new variable through json.parse Turn to object ;

2. Recursive implementation

原网站

版权声明
本文为[Stand on the bridge and bake cold noodles]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/163/202206122029151732.html