多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
## bind + [link](./bind "Link to this entry.") + [source](https://github.com/lodash/lodash/blob/4.5.0正式版/lodash.src.js#L8423 "View in source.") + [npm](https://www.npmjs.com/package/lodash.bind "See the npm package.") ``` _.bind(func, thisArg, [partials]) ``` 创建一个函数 `func`,这个函数的 `this` 会被绑定在 `thisArg`。 并且任何附加在 `_.bind` 的参数会被传入到这个绑定函数上。 这个 `_.bind.placeholder` 的值,默认是以 `_` 作为附加部分参数的占位符。 **注意:** 不同于原生的 Function#bind,这个方法不会设置绑定函数的 length 属性。 ### 参数 1. func (Function) 要绑定的函数 2. thisArg (\*) 这个 `this` 会被绑定给 `func`。 3. [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!' // 使用了占位符 var bound = _.bind(greet, object, _, '!'); bound('hi'); // => 'hi fred!' ```