2.1.2 • Published 6 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
6 years ago
2.1.1
6 years ago
2.1.0
6 years ago
2.0.23
6 years ago
2.0.22
6 years ago
2.0.21
6 years ago
2.0.20
6 years ago
2.0.19
6 years ago
2.0.18
6 years ago
2.0.17
6 years ago
2.0.16
6 years ago
2.0.15
6 years ago
2.0.14
6 years ago
2.0.13
6 years ago
2.0.12
6 years ago
2.0.11
6 years ago
2.0.10
6 years ago
2.0.9
6 years ago
2.0.8
6 years ago
2.0.7
6 years ago
2.0.6
6 years ago
2.0.5
6 years ago
2.0.4
6 years ago
2.0.3
6 years ago
2.0.2
6 years ago
2.0.1
6 years ago
2.0.0
6 years ago
1.1.3
7 years ago
1.1.2
7 years ago
1.1.1
8 years ago
1.1.0
8 years ago
1.0.0
8 years ago