Created
February 16, 2014 04:13
-
-
Save goliatone/9029106 to your computer and use it in GitHub Desktop.
Deep extend method
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
var extend = function extend(target) { | |
var sources = [].slice.call(arguments, 1); | |
sources.forEach(function (source) { | |
for (var property in source) { | |
if(source[property] && source[property].constructor && | |
source[property].constructor === Object){ | |
target[property] = target[property] || {}; | |
target[property] = extend(target[property], source[property]); | |
} else target[property] = source[property]; | |
} | |
}); | |
return target; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment