This is very easy to test by just running the code in an environment that supports classes:
class Base {
constructor (x) {
console.log('Base constructor called', x);
}
}
class TestA extends Base {}
class TestB extends Base {
constructor (x) {
super(x);
}
}
new TestA('a');
new TestB('b');
This results in the following output:
Base constructor called a
Base constructor called b
So yes, when you do not specify the constructor for the inheriting type, the base’s constructor is automatically called. Of course, if you want to have a different signature, or want to perform some other tasks, you will have to implement your own constructor for the inheriting type, and then also make a super()
call in order to have the base’s constructor be executed.
This is also formalized in the specification:
If constructor is empty, then,
If ClassHeritageopt is present, then
Let constructor be the result of parsing the source text
constructor(... args){ super (...args);}
using the syntactic grammar with the goal symbol MethodDefinition.
Else,
Let constructor be the result of parsing the source text
constructor( ){ }
using the syntactic grammar with the goal symbol MethodDefinition.