Travis build: 1465

This commit is contained in:
30secondsofcode
2018-01-28 12:45:54 +00:00
parent abac9e4c78
commit 6b22af223a
2 changed files with 45 additions and 2 deletions

View File

@ -220,6 +220,7 @@ average(1, 2, 3);
<details> <details>
<summary>View contents</summary> <summary>View contents</summary>
* [`attempt`](#attempt)
* [`bind`](#bind) * [`bind`](#bind)
* [`bindKey`](#bindkey) * [`bindKey`](#bindkey)
* [`chainAsync`](#chainasync) * [`chainAsync`](#chainasync)
@ -3465,6 +3466,37 @@ tomorrow(); // 2017-12-27 (if current date is 2017-12-26)
--- ---
## 🎛️ Function ## 🎛️ Function
### attempt
Attempts to invoke a function with the provided arguments, returning either the result or the caught error object.
Use a `try... catch` block to return either the result of the function or an appropriate error.
```js
const attempt = (fn, ...args) => {
try {
return fn(args);
} catch (e) {
return e instanceof Error ? e : new Error(e);
}
};
```
<details>
<summary>Examples</summary>
```js
var elements = attempt(function(selector) {
return document.querySelectorAll(selector);
}, '>_>');
if (elements instanceof Error) elements = []; // elements = []
```
</details>
<br>[⬆ Back to top](#table-of-contents)
### bind ### bind
Creates a function that invokes `fn` with a given context, optionally adding any additional supplied parameters to the beginning of the arguments. Creates a function that invokes `fn` with a given context, optionally adding any additional supplied parameters to the beginning of the arguments.

File diff suppressed because one or more lines are too long