Skip to content

Instantly share code, notes, and snippets.

@NeoTech
Created September 22, 2015 14:04
Show Gist options
  • Save NeoTech/3c36ed06bed52487be2f to your computer and use it in GitHub Desktop.
Save NeoTech/3c36ed06bed52487be2f to your computer and use it in GitHub Desktop.
How to properly clone an object/constructor in Javascript without loosing data.
Object.deepExtend = function(destination, source) {
for (var property in source) {
if (source[property] && source[property].constructor && source[property].constructor === Object) {
destination[property] = destination[property] || {};
arguments.callee(destination[property], source[property]);
} else {
destination[property] = source[property];
}
}
return destination;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment