
面试官:super() 和 super(props) 有什么区别?
一、ES6 类
在 ES6 中,通过 extends 关键字实现类的继承,方式如下:
class sup {
constructor(name) {
this.name = name;
}
printName() {
console.log(this.name);
}
}
class sub extends sup {
constructor(name, age) {
super(name); // super
代表的事父类的构造函数
this.age = age;
}
printAge() {
console.log(this.age);
}
}
let jack = new sub("jack", 20);
jack.printName(); //
输出
: jack
jack.printAge(); //
输出
: 20