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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -