ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
## bindKey + [link](./bindKey "Link to this entry.") + [source](https://github.com/lodash/lodash/blob/4.5.0正式版/lodash.src.js#L8475 "View in source.") + [npm](https://www.npmjs.com/package/lodash.bindkey "See the npm package.") ``` _.bindKey(object, key, [partials]) ``` 创建一个函数。 该方法绑定 `object[key]` 的方法。 任何附加在 `_.bindKey` 的参数会预设到该绑定函数上。 这个方法与 `_.bind` 的不同之处在于允许重写绑定函数即使它还不存在。 浏览 [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern) 了解更多详情。 这个 `_.bindKey.placeholder` 的值,默认是以 `_` 作为附加部分参数的占位符。 ### 参数 1. object (Object) 需要绑定函数的对象 2. key (string) 需要绑定函数对象的键 3. [partials] (...*) 附加的部分参数 ### 返回值 (Function) 返回新的绑定函数 ### 示例 ``` var object = { 'user': 'fred', 'greet': function(greeting, punctuation) { return greeting + ' ' + this.user + punctuation; } }; var bound = _.bindKey(object, 'greet', 'hi'); bound('!'); // => 'hi fred!' object.greet = function(greeting, punctuation) { return greeting + 'ya ' + this.user + punctuation; }; bound('!'); // => 'hiya fred!' // 使用了占位符 var bound = _.bindKey(object, 'greet', _, '!'); bound('hi'); // => 'hiya fred!' ```