Travis build: 1387

This commit is contained in:
30secondsofcode
2018-01-24 12:16:45 +00:00
parent e501e7170c
commit 6353f9b51a
3 changed files with 46 additions and 4 deletions

View File

@ -217,6 +217,7 @@ average(1, 2, 3);
<details>
<summary>View contents</summary>
* [`bind`](#bind)
* [`chainAsync`](#chainasync)
* [`compose`](#compose)
* [`composeRight`](#composeright)
@ -3153,6 +3154,37 @@ tomorrow(); // 2017-12-27 (if current date is 2017-12-26)
---
## 🎛️ Function
### bind
Creates a function that invokes `fn` with a given context, optionally adding any additional supplied parameters to the beginning of the arguments.
Return a `function` that uses `Function.apply()` to apply the given `context` to `fn`.
Use `Array.concat()` to prepend any additional supplied parameters to the arguments.
```js
const bind = (fn, context, ...args) =>
function() {
return fn.apply(context, args.concat(...arguments));
};
```
<details>
<summary>Examples</summary>
```js
function greet(greeting, punctuation) {
return greeting + ' ' + this.user + punctuation;
}
const freddy = { user: 'fred' };
const freddyBound = bind(greet, freddy);
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

@ -16,7 +16,7 @@ const bind = (fn, context, ...args) =>
function greet(greeting, punctuation) {
return greeting + ' ' + this.user + punctuation;
}
const freddy = { 'user': 'fred' };
const freddy = { user: 'fred' };
const freddyBound = bind(greet, freddy);
console.log(freddyBound('hi','!')); // 'hi fred!'
console.log(freddyBound('hi', '!')); // 'hi fred!'
```