主题
bindAll
js
_.bindAll(object, methodNames)
将对象的方法绑定到对象本身,覆盖现有方法。
¥Binds methods of an object to the object itself, overwriting the existing method.
注意:此方法不设置绑定函数的 "length" 属性。
¥Note: This method doesn't set the "length" property of bound functions.
新增于
¥Since
0.1.0
参数
¥Arguments
object
(对象):要绑定并分配绑定方法的对象。¥
object
(Object): The object to bind and assign the bound methods to.methodNames
(...(字符串|字符串[])):要绑定的对象方法名称。¥
methodNames
(...(string|string[])): The object method names to bind.
返回
¥Returns
(对象):返回 object
。
¥(Object): Returns object
.
示例
¥Example
js
var view = {
'label': 'docs',
'click': function() {
console.log('clicked ' + this.label);
}
};
_.bindAll(view, ['click']);
jQuery(element).on('click', view.click);
// => Logs 'clicked docs' when clicked.