javascript - What is the difference between deep and shallow cloning? -


if use splice clone array gives me shallow copy, missing? seems multilevel arrays not depth of array if understand correctly.

in shallow copy, if arrays (or object properties) references objects, references copied.

var = [{name: "bob"}]; var b = a.slice(0); b[0].name = "tom"; alert(a[0].name); // "tom" 

a "deep" copy makes sure result contains new copies of referenced objects original data structure. performing deep copy can problematic, depending on nature of objects involved.


Comments

Popular posts from this blog

Winapi c++: DialogBox hangs when breaking a loop -

vb.net - Font adding using PDFsharp -

javascript - jQuery iScroll clickable list elements while retaining scroll? -