function getType(o) {
var _t;
return ((_t = typeof (o)) == "object" ? o == null && "null"
|| Object.prototype.toString.call(o).slice(8, -1) : _t)
.toLowerCase();
}
執行結果:
getType("abc"); //string
getType(true); //boolean
getType(123); //number
getType([]); //array
getType({}); //object
getType(function(){}); //function
getType(new Date); //date
getType(new RegExp); //regexp
getType(Math); //math
getType(null); //null