Travis build: 1465
This commit is contained in:
32
README.md
32
README.md
@ -220,6 +220,7 @@ average(1, 2, 3);
|
||||
<details>
|
||||
<summary>View contents</summary>
|
||||
|
||||
* [`attempt`](#attempt)
|
||||
* [`bind`](#bind)
|
||||
* [`bindKey`](#bindkey)
|
||||
* [`chainAsync`](#chainasync)
|
||||
@ -3465,6 +3466,37 @@ tomorrow(); // 2017-12-27 (if current date is 2017-12-26)
|
||||
---
|
||||
## 🎛️ 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
|
||||
|
||||
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
Reference in New Issue
Block a user