In JavaScript, is constructor mandatory in a class?

后端 未结 2 1853
野性不改
野性不改 2021-02-07 02:16

I am reading about JavaScript class from the Mozilla documentation section of \'Class body and method definitions\'. Under the Constructor section, it states that

2条回答
  •  别那么骄傲
    2021-02-07 02:58

    No, It is not necessary. By default constructor is defined as :

    constructor() {}
    

    For inheritance we use this constructor to call super class as :

    constructor() {
        super.call()
    }
    

提交回复
热议问题