bindAll source npm
_.bindAll(object, methodNames)
Binds methods of an object to the object itself, overwriting the existing
method.
Note: This method doesn't set the "length" property of bound functions.
Arguments
- object (Object)
The object to bind and assign the bound methods to.
- methodNames (...(string|string[])
The object method names to bind, specified individually or in arrays.
Returns (Object)
Returns object
.
Example
var view = {
'label': 'docs',
'onClick': function() {
console.log('clicked ' + this.label);
}
};
_.bindAll(view, 'onClick');
jQuery('#docs').on('click', view.onClick);
// => logs 'clicked docs' when the element is clicked