Created
April 30, 2015 07:19
-
-
Save kitelife/fb2ea6cdebb90eed90c0 to your computer and use it in GitHub Desktop.
深拷贝
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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