jquery.js中数据检测toType是怎么实现的
let class2type = [];
"Boolean Number String Function Array Date RegExp Object Error Symbol".split(" ").forEach((name,i)=>{
class2type['[object '+name+']'] = name.toLowerCase();
})
function toType(obj){
if (obj == null){
console.log(1)
return obj +''
}
return typeof obj === 'function' || typeof obj === 'object'?typeof obj:class2type[Object.prototype.toString.call(obj)]
}
Object.prototype.tostring.call是怎么回事?
详细解析object.prototype.totring