Created
September 17, 2012 17:57
-
-
Save wilmoore/3738779 to your computer and use it in GitHub Desktop.
UnderscoreJS-inspired `merge` taking advantage of ES5 where possible
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
/** | |
* UnderscoreJS inspired `merge` | |
* UnderscoreJS calls it `extend` (overloaded in JS); `merge` feels more intention revealing | |
* This is naive as it always overwrites if the target property exists. | |
* | |
* @see https://github.com/documentcloud/underscore/blob/master/underscore.js#L727 | |
* @param {Object} target | |
* @return {Object} target | |
*/ | |
function merge(target) { | |
[].slice.call(arguments, 1).forEach(function(source) { | |
Object.keys(source).forEach(function(key){ | |
target[key] = source[key]; | |
}); | |
}); | |
return target; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment