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

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -