class Prople {constructor(name) {this.name = name;}eat() {console.log(`${this.name} eat something`)}
}//类
class Student extends Prople {constructor(name, number) {super(name);this.number = number;}sayHi() {console.log(`姓名 ${this.name} .学号 ${this.number}`)}
}class Teacher extends Prople {constructor(name, major) {super(name);this.major = major;}teach() {console.log(`姓名 ${this.name} .学号 ${this.major}`)}
}
//通过类声明实例
const xialuo = new Student('下落', 100);
console.log(xialuo.name);
console.log(xialuo.number);
xialuo.sayHi();
xialuo.eat();const geyao = new Teacher('hah', '66');
console.log(geyao.name);
console.log(geyao.major);
geyao.teach();
geyao.eat();
运行结果