//动态原型模式创建对象
//this指向的类的实例,谁调用指向谁,可以创建实例的私有属性和方法
//prototype指向原型,可以创建类的公共属性和方法
//constructor指向类的构造方法
function Person(name) {
this.name = name;
if (typeof this.say!=="function"){
Person.prototype.say=function(){
console.log(`${this.name}say:你好`);
}
}
}
var p1 = new Person("猪八戒");
console.log("say" in p1);//true
console.log(p1.hasOwnProperty("say"));//false
console.log(p1.__proto__.hasOwnProperty("say"));//true
console.log(p1.__proto__.constructor===Person);//true
p1.say();