When you extend another function, then super(..) should be the first expression in the constructor . Only then can you use this .
var EventEmitter = require('events'); class Foo extends EventEmitter { constructor() { super(); this.name = 'foo'; } print() { console.log(this.name); } } new Foo().print();
This is similar to the fact that the class you are leaving should be given the opportunity to set variables before the current class redefines them.
In addition, an implicit call to super() means that we pass undefined parameters declared in the constructor parent. That is why this is not done by default.
thefourtheye
source share