js判断数据类型的自定义函数type
function type(obj){switch(obj){
case null:
return "null";
case undefined:
return "undefined";
}
var s=Object.prototype.toString.call(obj);
switch(s){
case "":
return "string";
case "":
return "number";
case "":
return "boolean";
case "":
return "array";
case "":
return "date";
case "":
return "function";
case "":
return "regExp";
case "":
return "object";
default:
return "object";
}
}]
页:
[1]