typeof与instanceof区别
function getType(obj){
let type = typeof obj;
if (type !== “object”) { // 先进行typeof判断,如果是基础数据类型,直接返回
return type;
}
// 对于typeof返回结果是object的,再进行如下的判断,正则返回结果
return Object.prototype.toString.call(obj).replace(/^[object (\S+)]$/, ‘$1’);
}
...
原创
2021-03-13 10:06:04 ·
110 阅读 ·
2 评论