_.bind
语法:
_.bind(func, thisArg, [partials])源代码链接:source
npm包链接:npm package
描述:
创建一个调用func的函数,thisArg绑定func函数中的this ,并且func函数会接收partials附加参数。
_.bind.placeholder值,默认是以_作为附加部分参数的占位符。
注意:不同于原生的Function#bind,这个方法不会设置绑定函数的 "length" 属性。
开始版本:0.1.0
参数:
func (Function): 绑定的函数。thisArg (*): func 绑定的this对象。[partials] (...*): 附加的部分参数。
返回值:
(Function): 返回新的绑定函数。
例子:
var greet = function(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!'Last updated
Was this helpful?