请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

关于invariant的问题

function invariant(condition, format, a, b, c, d, e, f) {
  validateFormat(format);
  console.log('invariant', condition, format, a,b,c,d,e,f)
  if (!condition) {
    var error = void 0;
    if (format === undefined) {
      error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
    } else {
      var args = [a, b, c, d, e, f];
      var argIndex = 0;
      // /%s/g全局匹配字符串中'%s'字符串,第二个参数可以是字面值也可以是一个函数,若是字面值,那么它会
      // 全局替换成这个字面值,若是一个函数的话,那么它会递归正则里面的每个值,比如:format中有3个%s,那么会
      // 对这3个%s进行单独的值替换
      error = new Error(format.replace(/%s/g, function () {
        return args[argIndex++];
      }));
      error.name = 'Invariant Violation';
    }

    error.framesToPop = 1; // we don't care about invariant's own frame
    throw error;
  }
}

validateFormat在format为空的时候报错,那么下面为何还format==undefined,这个时候还起作用吗?有必要再做一次判断吗?
还有framesToPop是干啥的?

正在回答 回答被采纳积分+3

1回答

Jokcy 2019-11-24 19:18:12

format==undefined是啥,能把调用invariant的代码给出么

0 回复 有任何疑惑可以回复我~
  • 提问者 qq_crusader_1 #1
    invariant(
        typeof partialState === 'object' ||
          typeof partialState === 'function' ||
          partialState == null,
        'setState(...): takes an object of state variables to update or a ' +
          'function which returns an object of state variables.',
      );
    回复 有任何疑惑可以回复我~ 2019-11-30 11:07:26

相似问题

登录后可查看更多问答,登录/注册

问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号