Date

“Function” Methods

_.bind(func, thisArg, [partials])

source npm package

Creates a function that invokes func with the this binding of thisArg and partials prepended to the arguments it receives.

The _.bind.placeholder value, which defaults to _ in monolithic builds, may be used as a placeholder for partially applied arguments.

Note: Unlike native Function#bind, this method doesn't set the "length" property of bound functions.



引入版本

0.1.0

参数
func (Function) : The function to bind.
thisArg (*) : The this binding of func.
[partials] (...*) : The arguments to be partially applied.

返回值
(Function) : Returns the new bound function.

示例
function greet(greeting, punctuation) {
  return greeting + ' ' + this.user + punctuation;
}
 
var object = { 'user''fred' };
 
var bound = _.bind(greet, object, 'hi');
bound('!');
// => 'hi fred!'
 
// Bound with placeholders.
var bound = _.bind(greet, object, _, '!');
bound('hi');
// => 'hi fred!'