class Person{
constructor(name){
this.name = name;
}
greet(){
console.log('Hello,my name is ' + this.name + 'and I am ' + this.age);
}
}
class Max extends Person {
constructor(age){
super('Max');
this.age = age;
}
greet(){
console.log('haha');
}
greetTwice(){
super.greet();
this.greet();
}
}
let max = new Max(27);
max.greetTwice();
console.log(max.__proto__ == Max.prototype); //true;
console.log(max.__proto__ == Person.prototype); //false;
为啥Max是继承了Person,但是他们的prototype却不一样?
肥皂起泡泡
相关分类