Last active
August 29, 2015 14:02
-
-
Save ben-bradley/4c5f6fdbe84c3c84f8d6 to your computer and use it in GitHub Desktop.
Deep Extend for JavaScript
This file contains hidden or 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
//http://andrewdupont.net/2009/08/28/deep-extending-objects-in-javascript/ | |
Object.deepExtend = function(dst, src) { | |
for (var prop in src) { | |
if (src[prop] && src[prop].constructor && src[prop].constructor === Object) { | |
dst[prop] = dst[prop] || {}; | |
arguments.callee(dst[prop], src[prop]); | |
} else { | |
dst[prop] = src[prop]; | |
} | |
} | |
return dst; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment