js 继承
//父类 class Person{ constructor(name) { this.name = name } eat(){ console.log(`${this.name} eat something`) } } //子类 class Student extends Person{ constructor(name,number) { super(name); this.number = number } sayHI(){ console.log(`姓名 ${this.name} 学号 ${this.number} `) } } //实列 const std = new Student('周瑜',333) std.sayHI() std.eat()
//父类
class Person{
constructor(name) {
this.name = name
}
eat(){
console.log(`${this.name} eat something`)
}
}
//子类
class Student extends Person{
constructor(name,number) {
super(name);
this.number = number
}
sayHI(){
console.log(`姓名 ${this.name} 学号 ${this.number} `)
}
}
//实列
const std = new Student('周瑜',333)
std.sayHI()
std.eat()