const toType = function toType(obj) {
// null/undefined
if(obj == null) return obj+'';
let reg = /^\[object ([a-zA-Z0-9]+)\]$/;
// 引用数据类型
return typeof obj === 'object' || typeof obj === 'function' ?
// 正则捕获exec [Object xxx] 捕获到xxx并转成小写字符串输出
reg.exec(Object.prototype.toString.call(obj))[1].toLowerCase() :
// 原始值类型
typeof obj
}
检测数据类型的公用方法
最新推荐文章于 2022-06-06 12:54:11 发布