日期:2014-05-16 浏览次数:20529 次
var o=[];
alert(o instanceof Array);//true
alert(o instanceof Object);//true
var f=function(){}
alert(f instanceof Function);//true
alert(f instanceof Object);//true
var d=new Date(); alert(d instanceof Object);//true alert(d.constructor==Object);//false alert(d.constructor==Date);//true
var d=new Date();
alert(Object.prototype.toString.apply(d));//[object Date]
var a=[];
alert(Object.prototype.toString.apply(a));//[object Array]
function getType(x){
if(x==null){
return "null";
}
var t= typeof x;
if(t!="object"){
return t;
}
var c=Object.prototype.toString.apply(x);
c=c.substring(8,c.length-1);
if(c!="Object"){
return c;
}
if(x.constructor==Object){
return c
}
if("classname" in x.prototype.constructor
&& typeof x.prototype.constructor.classname=="string"){
return x.constructor.prototype.classname;
}
return "<unknown type>";
}