class的构造器外部函数eat相当于手动继承写 People.prototype.eat()
改变People.prototype.eat(),会改变内部的class内部的eat
super(name)相当于手动继承 People.prototype.constructor.call(this,name)
People.prototype.constructor == People
class People {
constructor(name) {
this.name = name
}
//class的函数eat相当于手动继承写 People.prototype.eat()
eat() {
console.log('eat something...');
}
}
//改变People.prototype.eat(),会改变内部的class内部的eat
People.prototype.eat = function () {
console.log('eat apple');
}
class Student extends People {
constructor(name, number) {
super(name)//
//相对于 手动继承方式中的People.prototype.constructor.call(this,name) OR People.call(name)
this.number = number
}
sayHi() {
console.log(
this.name,this.number
);
}
}
const XIALUO = new Student('夏洛', '13')
XIALUO.sayHi()
XIALUO.eat()//eat apple
console.log(XIALUO);
console.log(People.prototype.constructor == People);//true