title: Can I use this.on to listen to events in EventEmitter? Looking for correct usage of Eventmitter in class in javascript
body: <p>I am using <a href="https://github.com/primus/eventemitter3" rel="nofollow">EventEmitter3</a> which is an event module in my javascript code. It works just like the <code>event</code> module in Node.js. But I am facing problems to use it correctly. </p>
  
  <p>Normally if I use the module in my code, I would create an object of the <code>EventEmitter</code> and then use <code>object.emit</code> to fire the events and <code>object.on</code> to listen to the events. And what I normally do is put <code>object.on</code> in another class so it works perfectly.</p>
  
  <p>Now I try to organize my code in ES6 classes. So I extend <strong>EventEmitter</strong> in my customized class. Assume it is called <strong>ClassA</strong>, which is a subclass of <strong>EventEmitter</strong>. If I listen to its own event in the class definition, like this:</p>
  
  <pre><code>import EventEmitter from 'eventemitter3';
  
  class ClassA extends EventEmitter {
    constructor() {
      ...
    }
  
    method() {
      this.emit('send');
    }
  
    this.on('send', function(data) {
      // Do something with data
    });
  }
  </code></pre>
  
  <p>I am getting an Unexpected token error on <code>this.on</code> line. But I am not sure how to listen to the class's own event inside the class or is this even doable? Do I have to put the listeners outside of the class definition?</p>