Skip to content

Instantly share code, notes, and snippets.

@davidlonjon
Last active December 15, 2015 05:39
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 davidlonjon/5210183 to your computer and use it in GitHub Desktop.
Save davidlonjon/5210183 to your computer and use it in GitHub Desktop.
JavaScript: Clone Object
// Taken from http://stackoverflow.com/questions/728360/copying-an-object-in-javascript
clone = function(obj) {
if (null == obj || "object" != typeof obj) return obj;
var copy = obj.constructor();
for (var attr in obj) {
if (obj.hasOwnProperty(attr)) copy[attr] = obj[attr];
}
return copy;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment