Skip to content

Instantly share code, notes, and snippets.

@kitelife
Created April 30, 2015 07:19
Show Gist options
  • Save kitelife/fb2ea6cdebb90eed90c0 to your computer and use it in GitHub Desktop.
Save kitelife/fb2ea6cdebb90eed90c0 to your computer and use it in GitHub Desktop.
深拷贝
function deepCopy(p, c) {
c = c || {};
for (var i in p) {
if (p.hasOwnProperty(i)) {
if (typeof p[i] === 'object') {
c[i] = Array.isArray(p[i]) ? [] : {};
deepCopy(p[i], c[i]);
} else {
c[i] = p[i];
}
}
}
return c;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment