导航

JS中用来判断对象类型

Posted on 2011-01-13 09:15  fxcser  阅读(362)  评论(0)    收藏  举报

1、利用typeof来判断            

 

if(typeof num == "string")

 

2、利用构造函数属性来判断

 

if(num.constructor == String)

 

变量typeof变量变量.构造函数
{an:"object"} object Object
[an,"object"] object Array
function(){} function Function
"a string" string String
55 number Number
true boolean Boolean
new User() object User