Last updated 5 years ago
Was this helpful?
语法:
_.attempt(func, [args])
源代码链接:
npm包链接:
描述:
尝试调用func,返回结果 或者 捕捉错误对象。任何附加的参数都会在调用时传给func。
func
开始版本:3.0.0
参数:
func (Function): 要尝试调用的函数。
func (Function)
[args] (...*): 调用func时,传递的参数。
[args] (...*)
返回值:
(*): 返回func结果或者错误对象。
(*)
例子:
// Avoid throwing errors for invalid selectors. var elements = _.attempt(function(selector) { return document.querySelectorAll(selector); }, '>_>'); if (_.isError(elements)) { elements = []; }