多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
## bindAll + [link](./bindAll "Link to this entry.") + [source](https://github.com/lodash/lodash/blob/4.5.0正式版/lodash.src.js#L13128 "View in source.") + [npm](https://www.npmjs.com/package/lodash.bindall "See the npm package.") ``` _.bindAll(object, methodNames) ``` 绑定对象的方法到对象本身,覆盖已存在的方法。 **注意:** 这个方法不会设置 "length" 属性到约束的函数。 ### 参数 1. object (Object) 要绑定的对象 2. methodNames (...(string|string[]) 要绑定的方法名 单独指定或指定在数组中。 ### 返回值 (Object) 返回对象 ### 示例 ``` var view = { 'label': 'docs', 'onClick': function() { console.log('clicked ' + this.label); } }; _.bindAll(view, 'onClick'); jQuery(element).on('click', view.onClick); // => logs 'clicked docs' when clicked ```