标签:return temp 判断 包装类 object tar get 封装 prot
// 封装type,区分typeof方法
// 1)先分类,原始值,引用值
// 2)区分引用值,先判断是不是null
// 数组,对象,包装类(new number )会返回object,通过Object.prototype.toString
function type(target){
var ret = typeof(target);
var template = {
"[object Array]": "array",
"[object Object]": "object",
"[object Number]": "number - object",
"[object Boolean]": "boolean - object",
"[object String]": "string - object",
};
if(target === null){
return null;
}else if(ret == "object"){
var str = Object.prototype.toString.call(target);
return template[str];
}else{
return ret;
}
}
封装type,判断对象typeof类型
标签:return temp 判断 包装类 object tar get 封装 prot
原文地址:https://www.cnblogs.com/Rooney10/p/13027079.html