Skip to content

Instantly share code, notes, and snippets.

@Go7hic
Last active August 2, 2017 07:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Go7hic/c28533a9e52a99ac2bf81db0908ae22f to your computer and use it in GitHub Desktop.
Save Go7hic/c28533a9e52a99ac2bf81db0908ae22f to your computer and use it in GitHub Desktop.
JS 深浅拷贝 #tags: 深浅拷贝
```
function deepCopy(p, c) {
    var c = c || {};
    for (var i in p) {
      if (typeof p[i] === 'object') {
        c[i] = (p[i].constructor === Array) ? [] : {};
        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