日期:2014-05-16  浏览次数:20333 次

精确获取JS变量类型

??? 在获取js变量类型时,可以使用typeOf()方法获取,但使用此方法获取的变量类型并不是精确,对于一切new出来的变量,js会一律将其类型判定为object。

?? 例如:

??

var nums =  new Array(1,2,3);
var date = new Date();
alert(typeof(nums ));  //object
alert(typeof(date ));  //object

????使用下面的函数可精确获取js变量的类型:

 function getParamType(param) {   
        return ((_t = typeof (param)) == "object" ? Object.prototype.toString.call(param).slice(8, -1) : _t).toLowerCase();   
     }  

?