关于invariant的问题
来源:2-4 react-component
qq_crusader_1
2019-11-23
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是干啥的?
写回答
1回答
-
Jokcy
2019-11-24
format==undefined是啥,能把调用invariant的代码给出么
012019-11-30
相似问题
老师,关于重名的这个方法
回答 1
set和useState的对应问题
回答 1