原型链
下面定义了People类,Student类依赖与People。A为Student的实例
class People {
constructor (name) {
this.name = name
}
sayHi () {
console.log(`${this.name} say hi`);
}
}
class Student extends People {
constructor (name, grade) {
// 运行父类的constructor,并传参数
super(name)
this.grade = grade
}
sayGrade () {
console.log(`${this.name} is ${this.grade} grade`);
}
}
const A = new Student('wangyu', 8)
它们之间的原型链关系为:
