Allow _.attempt to provide additional arguments to func. [closes #929]

This commit is contained in:
jdalton
2015-02-06 23:09:52 -08:00
parent 82c7a22d27
commit 5ab79f292b
2 changed files with 16 additions and 11 deletions

View File

@@ -10140,8 +10140,8 @@
/*------------------------------------------------------------------------*/
/**
* Attempts to invoke `func`, returning either the result or the caught
* error object.
* Attempts to invoke `func`, returning either the result or the caught error
* object. Any additional arguments are provided to `func` when it is invoked.
*
* @static
* @memberOf _
@@ -10151,9 +10151,9 @@
* @example
*
* // avoid throwing errors for invalid selectors
* var elements = _.attempt(function() {
* var elements = _.attempt(function(selector) {
* return document.querySelectorAll(selector);
* });
* }, '>_>');
*
* if (_.isError(elements)) {
* elements = [];
@@ -10161,7 +10161,7 @@
*/
function attempt(func) {
try {
return func();
return func.apply(undefined, baseSlice(arguments, 1));
} catch(e) {
return isError(e) ? e : Error(e);
}