hasOwnProperty:是用来判断一个对象是否有你给出名称的属性或对象。不过需要注意的是,此方法无法检查该对象的原型链中是否具有该属性,该属性必须是对象本身的一个成员。
isPrototypeOf:是用来判断要检查其原型链的对象是否存在于指定对象实例中,是则返回true,否则返回false。
function SetObj(name,age){
this.name=name;
this.age=age;
}
SetObj.prototype.sayName=function (){
console.log("xxx")
}
var b1=new SetObj("xiaohua",45);
console.log(b1.hasOwnProperty("name")); //true
console.log(b1.hasOwnProperty("sayName")); //false
console.log(SetObj.prototype.hasOwnProperty("sayName")); //true
console.log(SetObj.prototype.isPrototypeOf(b1));//true