bind-defaults
Version:
A utility for enhancing functions by binding default values to their first parameter
14 lines (12 loc) • 432 B
JavaScript
function bindDefaults(originalFunction, defaults) {
const originalFunctionName = originalFunction.name;
const boundFunction = function (options, ...args) {
const mergedOptions = Object.assign({}, defaults, options);
return originalFunction.call(this, mergedOptions, ...args);
};
Object.defineProperty(boundFunction, 'name', {
value: originalFunctionName
});
return boundFunction;
}
export { bindDefaults };