hasOwnProperty的使用

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

你可能感兴趣的:(hasOwnProperty的使用)