How to write self-calling function in es6 class?

class A () {
created () {

 alert(1);

}
}

for example, var a=new A ();
how to self-call the created method after creating an object, just like the vue hook

Mar.28,2021


class A{
  constructor(){
    //this.test()
  }
  test(){
    alert(1);
  }
}
var a = new A(); //
a.test(); //1
Menu