-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Labels
Description
static JsType(obj) {
let class2type = {};
// 生成class2type映射
"Boolean Number String Function Array Date RegExp Object Error".split(" ").map(function(item, index) {
class2type["[object " + item + "]"] = item.toLowerCase();
})
// 一箭双雕 undefined null 值相等 类型不等
if (obj == null) {
return obj + "";
}
// 优先ES6方法判断数组类型
if(Array.isArray(obj)){
return "array"
}
return typeof obj === "object" || typeof obj === "function" ?
class2type[Object.prototype.toString.call(obj)] || "object" :
typeof obj;
}