hasOwnProperty和isPrototypeOf
hasOwnProperty:是用来判断一个对象是否有你给出名称的属性或对象,此方法无法检查该对象的原型链中是否具有该属性,该属性必须是对象本身的一个成员。
isPrototypeOf是用来判断要检查其原型链的对象是否存在于指定对象实例中,是则返回true,否则返回false。
in 操作检查对象中是否有名为 property 的属性。也可以检查对象的原型,判断该属性是否为原型链的一部分.
hasOwnProperty:var obj = {a:1,b:2}obj.hasOwnProperty('a')isPrototypeOf:function F(){}var fn = new F()F.prototype.isPrototypeOf(fn)
function A () { this.a = 1;}function B () { this.b = 2;}B.prototype = new A();B.prototype.constructor = B;function C () { this.c = 3;}C.prototype = new B();C.prototype.constructor = C;var c = new C();// instanceof expects a constructor functionc instanceof A; // truec instanceof B; // truec instanceof C; // true// isPrototypeOf, can be used on any objectA.prototype.isPrototypeOf(c); // trueB.prototype.isPrototypeOf(c); // trueC.prototype.isPrototypeOf(c); // true
var a = [];Array.prototype.isPrototypeOf(a) //truea instanceof Array //true