Creates a function that invokes the method at a given key of an object, optionally prepending any additional supplied parameters to the arguments.
function
that uses Function.prototype.apply()
to bind context[fn]
to context
....
) to prepend any additional supplied parameters to the arguments.const bindKey = (context, fn, ...boundArgs) => (...args) =>
context[fn].apply(context, [...boundArgs, ...args]);
const freddy = {
user: 'fred',
greet: function(greeting, punctuation) {
return greeting + ' ' + this.user + punctuation;
}
};
const freddyBound = bindKey(freddy, 'greet');
console.log(freddyBound('hi', '!')); // 'hi fred!'
Would you like to help us improve 30 seconds of code?Take a quick survey
JavaScript, Function
Creates a function that invokes fn
with a given context, optionally prepending any additional supplied parameters to the arguments.
JavaScript, Function
Creates a function that invokes fn
with partials
prepended to the arguments it receives.
JavaScript, Function
Creates a function that will invoke a predicate function for the specified property on a given object.