Merge remote-tracking branch 'origin/master'

This commit is contained in:
Angelos Chalaris
2018-01-24 14:32:25 +02:00
3 changed files with 48 additions and 2 deletions

View File

@ -218,6 +218,7 @@ average(1, 2, 3);
<summary>View contents</summary>
* [`bind`](#bind)
* [`bindKey`](#bindkey)
* [`chainAsync`](#chainasync)
* [`compose`](#compose)
* [`composeRight`](#composeright)
@ -3185,6 +3186,39 @@ console.log(freddyBound('hi', '!')); // 'hi fred!'
<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
Chains asynchronous functions.

File diff suppressed because one or more lines are too long

View File

@ -17,7 +17,7 @@ const freddy = {
user: 'fred',
greet: function(greeting, punctuation) {
return greeting + ' ' + this.user + punctuation;
},
}
};
const freddyBound = bindKey(freddy, 'greet');
console.log(freddyBound('hi', '!')); // 'hi fred!'