js 获取数据类型


function
getType(obj){ return (obj === null && 'Null') || (obj === undefined && 'Undefined') || Object.prototype.toString.call(obj).slice(8,-1); } getType(null); "Null" getType(undefined); "Undefined" getType(false); "Boolean" getType(NaN); "Number" getType([]); "Array" getType({}); "Object" getType(/x/); "RegExp" getType(new Date); "Date" getType(function(){}); "Function" getType(Function); "Function" getType(''); "String"

 

posted @ 2015-02-07 16:46  北京-木木  阅读(325)  评论(0编辑  收藏  举报