mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 01:17:50 +00:00
Bump to v3.6.0.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import isError from '../lang/isError';
|
||||
import restParam from '../function/restParam';
|
||||
|
||||
/**
|
||||
* Attempts to invoke `func`, returning either the result or the caught error
|
||||
@@ -7,7 +8,7 @@ import isError from '../lang/isError';
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Utility
|
||||
* @param {*} func The function to attempt.
|
||||
* @param {Function} func The function to attempt.
|
||||
* @returns {*} Returns the `func` result or error object.
|
||||
* @example
|
||||
*
|
||||
@@ -20,19 +21,12 @@ import isError from '../lang/isError';
|
||||
* elements = [];
|
||||
* }
|
||||
*/
|
||||
function attempt() {
|
||||
var func = arguments[0],
|
||||
length = arguments.length,
|
||||
args = Array(length ? (length - 1) : 0);
|
||||
|
||||
while (--length > 0) {
|
||||
args[length - 1] = arguments[length];
|
||||
}
|
||||
var attempt = restParam(function(func, args) {
|
||||
try {
|
||||
return func.apply(undefined, args);
|
||||
} catch(e) {
|
||||
return isError(e) ? e : new Error(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export default attempt;
|
||||
|
||||
Reference in New Issue
Block a user