Last active
April 5, 2017 08:12
-
-
Save MOOOWOOO/8a7e4ed7a4e70fd3bfb382cf8b07cf2b to your computer and use it in GitHub Desktop.
javascript deepcopy
This file contains 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 cloneObject(obj) { | |
if (obj === null || typeof obj !== 'object') { | |
return obj | |
} | |
var temp = new obj.constructor() // give temp the original obj's constructor | |
for (var key in obj) { | |
temp[key] = cloneObject(obj[key]) | |
} | |
return temp | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment