class继承
关键:class里的extends和super关键字,继承效果与寄生组合继承一样
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| class Father { constructor(name) { this.name = name } showName() { console.log(this.name); } } class Son extends Father { constructor(name, age) { super(name) this.age = age } showAge() { console.log(this.age); } } const son = new Son('刘逍', 20) son.showName() son.showAge()
|