Last active
December 21, 2015 12:08
-
-
Save nonkr/6303366 to your computer and use it in GitHub Desktop.
Javascript Object deepExtend
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; | |
}; | |
var dstObj = Object.deepExtend({name:'jason'}, {age:18}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment