Merge remote-tracking branch 'origin/master'
This commit is contained in:
34
README.md
34
README.md
@ -218,6 +218,7 @@ average(1, 2, 3);
|
|||||||
<summary>View contents</summary>
|
<summary>View contents</summary>
|
||||||
|
|
||||||
* [`bind`](#bind)
|
* [`bind`](#bind)
|
||||||
|
* [`bindKey`](#bindkey)
|
||||||
* [`chainAsync`](#chainasync)
|
* [`chainAsync`](#chainasync)
|
||||||
* [`compose`](#compose)
|
* [`compose`](#compose)
|
||||||
* [`composeRight`](#composeright)
|
* [`composeRight`](#composeright)
|
||||||
@ -3185,6 +3186,39 @@ console.log(freddyBound('hi', '!')); // 'hi fred!'
|
|||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
|
### bindKey
|
||||||
|
|
||||||
|
Creates a function that invokes the method at a given key of an object, optionally adding any additional supplied parameters to the beginning of the arguments.
|
||||||
|
|
||||||
|
Return a `function` that uses `Function.apply()` to bind `context[fn]` to `context`.
|
||||||
|
Use `Array.concat()` to prepend any additional supplied parameters to the arguments.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const bindKey = (context, fn, ...args) =>
|
||||||
|
function() {
|
||||||
|
return context[fn].apply(context, args.concat(...arguments));
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
```js
|
||||||
|
const freddy = {
|
||||||
|
user: 'fred',
|
||||||
|
greet: function(greeting, punctuation) {
|
||||||
|
return greeting + ' ' + this.user + punctuation;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const freddyBound = bindKey(freddy, 'greet');
|
||||||
|
console.log(freddyBound('hi', '!')); // 'hi fred!'
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
### chainAsync
|
### chainAsync
|
||||||
|
|
||||||
Chains asynchronous functions.
|
Chains asynchronous functions.
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -17,7 +17,7 @@ const freddy = {
|
|||||||
user: 'fred',
|
user: 'fred',
|
||||||
greet: function(greeting, punctuation) {
|
greet: function(greeting, punctuation) {
|
||||||
return greeting + ' ' + this.user + punctuation;
|
return greeting + ' ' + this.user + punctuation;
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
const freddyBound = bindKey(freddy, 'greet');
|
const freddyBound = bindKey(freddy, 'greet');
|
||||||
console.log(freddyBound('hi', '!')); // 'hi fred!'
|
console.log(freddyBound('hi', '!')); // 'hi fred!'
|
||||||
|
|||||||
Reference in New Issue
Block a user