Skip to content

Instantly share code, notes, and snippets.

@OzieWest
Last active August 29, 2015 14:18
Show Gist options
  • Select an option

  • Save OzieWest/654453d107e8f4b08c10 to your computer and use it in GitHub Desktop.

Select an option

Save OzieWest/654453d107e8f4b08c10 to your computer and use it in GitHub Desktop.
JavaScript clone function
function clone(obj) {
if(obj == null || typeof(obj) != 'object')
return obj;
var temp = obj.constructor();
for(var key in obj) {
if(obj.hasOwnProperty(key)) {
temp[key] = clone(obj[key]);
}
}
return temp;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment