Under what circumstances can class in ES6 not declare constructor?

declare class class: in es6

class Template{
    constructor(){
       /**/
    }
    
    method(){
      /**/
    }
}

or

class Template{
    method(){
       /**/
    }
}

question: under what circumstances can class in
1.ES6 not declare constructor?
2. What"s the difference between the above code?


constructor is used for initialization. If nothing is done in it, there is no difference


when you don't need code to be executed at initialization, you don't need constructor

.

constructor is called automatically when the instance object is created

Menu