Created
September 19, 2012 18:32
-
-
Save ericf/3751340 to your computer and use it in GitHub Desktop.
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
let defaults = {}, | |
overrides = {}; | |
function foo(bar, options) { | |
// YUI | |
options = Y.merge(defaults, options, overrides); | |
// Underscore | |
options = _.extend({}, defaults, options, overrides); | |
// ES6 | |
options = [defaults, options, overrides].reduce(Object.assign, {}); | |
} | |
// ES6 YUI `Object.assign()` sugar. | |
Y.assign = function (target, ...sources) { | |
return sources.reduce(Object.assign, target); | |
}; | |
// ES6 back-compat `Y.merge()`. | |
Y.merge = function (...sources) { | |
return Y.assign({}, ...sources); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment