function Person(){
    Person.prototype.name = "china";
    Person.prototype.age = 2;
}

var person1 = new Person();

function hasPrototypeProperty(object,name){
    return !object.hasOwnProperty(name) && (name in object)
}

hasPrototypeProperty(person1,"name");  // true
person1.name = "jack";
hasPrototypeProperty(person1,"name");  //false

由于in操作符只要通过对象能访问到属性就返回true,hasOwnProperty()只在属性存在于实例中才返回true,因此只要in操作符返回true,hasOwnProperty()返回false,就可以确定属性是原型中的属性、

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-05
  • 2022-12-23
  • 2022-02-25
  • 2021-09-20
相关资源
相似解决方案