codecamp

Lodash _.attempt

_.attempt(func, [args])

尝试调用func,返回结果 或者 捕捉错误对象。任何附加的参数都会在调用时传给func。

添加版本

3.0.0

参数

  1. func (Function): 要尝试调用的函数。
  2. [args] (...*): 调用func时,传递的参数。

返回

(*): 返回func结果或者错误对象。

例子

// Avoid throwing errors for invalid selectors.
var elements = _.attempt(function(selector) {  return document.querySelectorAll(selector);}, '>_>');
 if (_.isError(elements)) {  elements = [];}


Lodash _.words
Lodash _.bindAll
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

Lodash 简介

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }