I have found that keyword "this" is "undefined" until super() is called, and I'm wondering where this behavior documented. I'm asking only to learn where I can lookup these answers myself (in the future).
Code that shows this behavior is given below:
class BaseClass {
constructor(){
this.baseVar = 1;
}
}
class SubClass extends BaseClass {
constructor(...args){
try {
console.log('this BEFORE calling super. this:', this);
} catch(ex) {
console.log('this BEFORE calling super. this: caused exception!');
}
super(...args);
this.subVar = 2;
console.log('this AFTER calling super. this:', this);
}
}
var base = new BaseClass();
var subclass = new SubClass();
The output from this is shown below:
this BEFORE calling super. this: caused exception!
this AFTER calling super. this: SubClass { baseVar: 1, subVar: 2 }