class Parent{
constructor(name,age){
this.name=name;
this.age=age
}
eat(){
console.log(`name: ${this.name} age: ${this.age}`);
}
}
class Son extends Parent{
constructor(name,age){
super(name,age);
this.age=age;
}
sayhi(){
console.log(`儿子 sayhi ${this.name} ${this.age}`)
}
}
const madongmei =new Son('马冬梅',50)
madongmei.__proto__===Son.prototype //全等 引用地址也相同
madongmei.prototype .__proto__===Parent.prototype //全等 引用地址也相同
madongmei.sayhi() // 儿子 sayhi 马冬梅 50
madongmei.__proto__.sayhi() // 儿子 sayhi undefined undefined (此时的this指向出现了问题,因此是undefined)
madongmei.__proto__.sayhi.call(madongmei) // 儿子 sayhi 马冬梅 50 (正确)
madongmei.hasOwnProperty('name') //true
madongmei.hasOwnProperty(''eat') //false