typeof总结:
typeof属于操作符;
typeof 1;//"number"
typeof (1);//"number"
.可以识别标准类型(Null除外)
.不能识别具体的对象类型(Function 除外)
instanceof总结:
.判别内置对象类型
[] instanceof Array; // true
/\d/ instanceof RegExp; // true
.不能判别原始类型
1 instanceof Number; // false
"jerry" instanceof String; //false
//能够判别自定义对象类型及父子类型
function Point(x,y){
this.x = x;
this.y = y;
}
function Circle(x,y,r){
Point.call(this,x,y);
this.radius = r;
}
Circle.prototype =new Point();
Circle.prototype.constructor = Circle;
var c = new Circle(1,1,2);
c instanceof Circle // true
c instanceof Point // true
Object.prototype.toString.call
function type(obj){
return Object.prototype.toString.call(obj).slice(8,-1);
}
.可以识别标准类型以及内置(build-in)对象类型
type(1)//"Number"
type(new Date) //"Date"
.不能识别自定义对象类型
function Point(x,y){
this.x = x;
this.y = y
}
type(new Point(1,2)); // "Object"