WEB开发网
开发学院网页设计JavaScript 获取JavaScript变量的类型(Finding Out Class Na... 阅读

获取JavaScript变量的类型(Finding Out Class Names of JavaScript Objects)

 2010-09-14 13:26:10 来源:WEB开发网   
核心提示: 输出如下:CodeInteger:42-toString()returns:42-typeof()returns:number-getObjectClass()returns:NumberBoolean:true-toString()returns:true-typeof()returns

输出如下:

Code

Integer:42
-toString()returns:42
-typeof()returns:number
-getObjectClass()returns:Number
Boolean:true
-toString()returns:true
-typeof()returns:boolean
-getObjectClass()returns:Boolean
String:"HelloWorld!"
-toString()returns:HelloWorld!
-typeof()returns:string
-getObjectClass()returns:String
Function:MyClass
-toString()returns:functionMyClass(){}
-typeof()returns:function
-getObjectClass()returns:Function
Regularexpression:/Matchthis!/
-toString()returns:/Matchthis!/
-typeof()returns:object
-getObjectClass()returns:RegExp
Intrinsicobject:document
-toString()returns:[object]
-typeof()returns:object
-getObjectClass()returns:undefined
Arrayobject:newArray(1,2,3)
-toString()returns:1,2,3
-typeof()returns:object
-getObjectClass()returns:Array
Dateobject:newDate()
-toString()returns:TueAug1917:32:34UTC+08002008
-typeof()returns:object
-getObjectClass()returns:Date
Objectobject:newObject()
-toString()returns:[objectObject]
-typeof()returns:object
-getObjectClass()returns:Object
MyClassobject:newMyClass()
-toString()returns:[objectObject]
-typeof()returns:object
-getObjectClass()returns:MyClass

我们可以看到,typeof 方法在数组、对象、自定义类型对象 的测试中,都只能返回“object”,而getObjectClass 方法则会获得真正的类型名称。获取JavaScript变量的类型(Finding Out Class Names of JavaScript Objects)

出处:http://blodfox777.cnblogs.com/

上一页  1 2 3 

Tags:获取 JavaScript 变量

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接