代码在类'构造函数后停止运行

时间:2017-10-23 13:57:23

标签: javascript

当我在扩展另一个类的类中声明构造函数方法时,在从类创建对象之后没有任何作用。为什么会这样?

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

1 个答案:

答案 0 :(得分:3)

在你的构造函数中调用super():

class test2 extends test {
  constructor(){ //this makes the alert(2); not working
    super(); 
  }
}