2.1.2 • Published 5 years ago
attempt-x v2.1.2
attempt-x
Invokes function, returning an object of the results.
module.exports(fn, [...args])
⇒ Object ⏏
This method attempts to invoke the function, returning either the result or the caught error object. Any additional arguments are provided to the function when it's invoked.
Kind: Exported function
Returns: Object - Returns an object of the result.
Param | Type | Description |
---|---|---|
fn | function | The function to attempt. |
...args | * | The arguments to invoke the function with. |
Example
import attempt from 'attempt-x';
function thrower() {
throw new Error('Threw');
}
attempt(thrower, 1, 2);
// {
// threw: true,
// value: // Error('Threw') object
// }
function sumArgs(a, b) {
return a + b;
}
attempt(sumArgs, 1, 2);
// {
// threw: false,
// value: 3
// }
const thisArg = [];
function pusher(a, b) {
return this.push(a, b);
}
attempt.call(thisArg, pusher, 1, 2);
// {
// threw: false,
// value: 2
// }
// thisArg => [1, 2];
2.1.2
5 years ago
2.1.1
5 years ago
2.1.0
5 years ago
2.0.23
5 years ago
2.0.22
5 years ago
2.0.21
5 years ago
2.0.20
5 years ago
2.0.19
5 years ago
2.0.18
5 years ago
2.0.17
5 years ago
2.0.16
5 years ago
2.0.15
5 years ago
2.0.14
5 years ago
2.0.13
5 years ago
2.0.12
5 years ago
2.0.11
5 years ago
2.0.10
5 years ago
2.0.9
5 years ago
2.0.8
5 years ago
2.0.7
5 years ago
2.0.6
5 years ago
2.0.5
5 years ago
2.0.4
5 years ago
2.0.3
5 years ago
2.0.2
5 years ago
2.0.1
5 years ago
2.0.0
5 years ago
1.1.3
6 years ago
1.1.2
6 years ago
1.1.1
7 years ago
1.1.0
7 years ago
1.0.0
7 years ago