MCPcopy Index your code
hub / github.com/ygs-code/vue / assertType

Function assertType

vue.js:2467–2497  ·  view source on GitHub ↗
(value, type)

Source from the content-addressed store, hash-verified

2465
2466 //获取type类型
2467 function assertType(value, type) {
2468 var valid;
2469 //getType检查函数是否是函数声明 如果是函数表达式或者匿名函数是匹配不上的
2470 //type 必须是String|Number|Boolean|Function|Symbol 构造函数
2471 var expectedType = getType(type);
2472
2473 //检测改函数是什么类型
2474 if (simpleCheckRE.test(expectedType)) { //type 必须是String|Number|Boolean|Function|Symbol 构造函数 这里才为真 (String|Number|Boolean|Function|Symbol)
2475 var t = typeof value;
2476 //转换成小写
2477 valid = t === expectedType.toLowerCase(); //布尔值
2478 // for primitive wrapper objects 对于原始包装对象
2479 if (!valid && t === 'object') {
2480 valid = value instanceof type;
2481 }
2482 } else if (expectedType === 'Object') {
2483 //检测是否是真正的对象
2484 valid = isPlainObject(value);
2485 } else if (expectedType === 'Array') {
2486 //检测是否是真正的数组
2487 valid = Array.isArray(value);
2488 } else {
2489 //判断 value 是否是type中的实例化对象
2490 valid = value instanceof type;
2491 }
2492 //返回出去值
2493 return {
2494 valid: valid,
2495 expectedType: expectedType
2496 }
2497 }
2498
2499 /**
2500 * Use function string name to check built-in types,

Callers 1

assertPropFunction · 0.85

Calls 2

getTypeFunction · 0.85
isPlainObjectFunction · 0.85

Tested by

no test coverage detected