知识点:Object.prototype.toString.call(obj) === ‘[object typeStr]’; typeStr
首字母必须大写
方法如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
function jsType(obj) { var toString=Object.prototype.toString; var toType = {}; var typeArr=['Undefined','Null','Boolean','Number','String','Object','Array','Function','Date','RegExp','Error','Arguments']; typeArr.map(function(item) { toType["[object " + item + "]"] = item.toLowerCase(); }); return typeof obj !== "object" ? typeof obj : toType[toString.call(obj)]; }
|