Created
September 22, 2015 14:04
-
-
Save NeoTech/3c36ed06bed52487be2f to your computer and use it in GitHub Desktop.
How to properly clone an object/constructor in Javascript without loosing data.
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
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