正确理解isPrototypeOf
A.isPrototypeOf(B)
- A是B的原型吗?是的返回True,反之返回False
代码
var f = function () { } //定义函数
f.prototype = { //函数的原型对象
a: 1,
b: function () {
return 2;
}
}
console.log(f.prototype.a); //读取函数的原型对象的属性a,返回1
console.log(f.prototype.b()); //读取函数的原型对象的属性b,返回2
var o = new f(); //实例对象
var b = f.prototype.isPrototypeOf(o);
console.log(b);