hasOwnProperty():判断对象是否有某个特定的属性。必须用字符串指定该属性。(例如,o.hasOwnProperty("name"))  //复制自w3cschool

IsPrototypeOf(): 判断该对象是否为另一个对象的原型。

不过hasOwnProperty 可以被赋值 ,这是不保险的。所以不能完全信任 hasOwnProperty 检测结果。

function Person(name,color){
    this.name=name;
    this.color=color;
}
Person.prototype.sayName=function(){
    alert(this.name);
}

var oP = new Person("aa",'red');
var oP2 = new Person('bb','blue');
oP.age=30;

console.log(oP.hasOwnProperty('name'));   //true
console.log(oP.hasOwnProperty('color'));  //true
console.log(oP.hasOwnProperty('age'));    //true
console.log(oP.hasOwnProperty('sayName'));//false
console.log(Person.prototype.isPrototypeOf(oP)); //true

 

相关文章:

  • 2022-12-23
  • 2021-11-21
  • 2021-09-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-28
相关资源
相似解决方案