hasOwnProperty()检车一个属性是存在于对象实例中(返回true),还是存在原型中(false)
hasOwnProperty()是从Object继承过来的。
function Person(name, age, job) {
this.name = name;
this.age = age;
this.job = job;
}
console.log(new Person("xuelian","","微信小程序"));
console.log(Person.hasOwnProperty("name"));//true
/**
* 原型模式
*/
function Person1(){}
Person1.prototype.name = "duxin";
Person1.prototype.age = 25;
Person1.prototype.job = "web wechat"
const person1 = new Person1();
console.log(person1.name);
console.log("name" in person1);//true
console.log(person1.hasOwnProperty("name"));//false
来源:CSDN
作者:潇湘一夜雨
链接:https://blog.csdn.net/xuelian3015/article/details/103496160