当我在扩展另一个类的类中声明构造函数方法时,在从类创建对象之后没有任何作用。为什么会这样?
class test{
}
class test2 extends test {
constructor(){ //this makes the alert(2); not working
}
}
alert(1); //this works
var e = new test2(); //nothing after this works
alert(2); //this doesn't run
答案 0 :(得分:3)
在你的构造函数中调用super():
class test2 extends test {
constructor(){ //this makes the alert(2); not working
super();
}
}