class继承

76 阅读1分钟

// 父类提取公共方法 class Person { constructor(name) { this.name = name; }

drink() { console.log('喝水'); } } // 使用class继承父类 :利用 extents 和 super 关键字 class Student extends Person { constructor(name, score) { super(name) this.score = score }

introduce() { console.log(我是${this.name},考了${this.score}); } }

const student = new Student('张三', 99) console.log(student.name, student.score); student.introduce() student.drink()

//如果不使用父类属性,就可以省略不写super class FC extends Person {

} let fc = new FC() fc.drink()