mirror of
				https://github.com/taixingyiji/openit.git
				synced 2025-11-04 04:32:24 +00:00 
			
		
		
		
	2022.07.20 16:18:09 更新订阅
This commit is contained in:
		
							
								
								
									
										35
									
								
								utils/rm/node_modules/lodash/attempt.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								utils/rm/node_modules/lodash/attempt.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
var apply = require('./_apply'),
 | 
			
		||||
    baseRest = require('./_baseRest'),
 | 
			
		||||
    isError = require('./isError');
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Attempts to invoke `func`, returning either the result or the caught error
 | 
			
		||||
 * object. Any additional arguments are provided to `func` when it's invoked.
 | 
			
		||||
 *
 | 
			
		||||
 * @static
 | 
			
		||||
 * @memberOf _
 | 
			
		||||
 * @since 3.0.0
 | 
			
		||||
 * @category Util
 | 
			
		||||
 * @param {Function} func The function to attempt.
 | 
			
		||||
 * @param {...*} [args] The arguments to invoke `func` with.
 | 
			
		||||
 * @returns {*} Returns the `func` result or error object.
 | 
			
		||||
 * @example
 | 
			
		||||
 *
 | 
			
		||||
 * // Avoid throwing errors for invalid selectors.
 | 
			
		||||
 * var elements = _.attempt(function(selector) {
 | 
			
		||||
 *   return document.querySelectorAll(selector);
 | 
			
		||||
 * }, '>_>');
 | 
			
		||||
 *
 | 
			
		||||
 * if (_.isError(elements)) {
 | 
			
		||||
 *   elements = [];
 | 
			
		||||
 * }
 | 
			
		||||
 */
 | 
			
		||||
var attempt = baseRest(function(func, args) {
 | 
			
		||||
  try {
 | 
			
		||||
    return apply(func, undefined, args);
 | 
			
		||||
  } catch (e) {
 | 
			
		||||
    return isError(e) ? e : new Error(e);
 | 
			
		||||
  }
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
module.exports = attempt;
 | 
			
		||||
		Reference in New Issue
	
	Block a user