The following code fails:
var EventEmitter = require('events');
class Foo extends EventEmitter{
constructor(){
this.name = 'foo';
}
print(){
this.name = 'hello';
console.log('world');
}
}
var f = new Foo();
console.log(f.print());
and prints error
this.name = 'foo';
^
ReferenceError: this is not defined
However when I am not extending EventEmitter it works fine.
Why is this happening and how can I resolve it? running nodejs 4.2.1