Skip to content

Instantly share code, notes, and snippets.

@MOOOWOOO
Last active April 5, 2017 08:12
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 MOOOWOOO/8a7e4ed7a4e70fd3bfb382cf8b07cf2b to your computer and use it in GitHub Desktop.
Save MOOOWOOO/8a7e4ed7a4e70fd3bfb382cf8b07cf2b to your computer and use it in GitHub Desktop.
javascript deepcopy
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