title: ExtJS - How to reference "self" in a custom function in a custom class?
body: <p>How do I reference an instance of a custom class inside a custom function defined within the class?</p>
  
  <p>I've extended a class through ExtJS4's class extension "mechanism", and I've a custom event handler that will be called when something is triggered, and I want to collapse the Panel when something is fired.</p>
  
  <p>However, in the event handler of the Reactor class below, "this" references EventTriggerer (The firer of the event) instead of the instance of the Reactor. How do I reference the instance of the EventReactor inside a custom function?</p>
  
  <p>Thanks!
  DashK</p>
  
  <pre><code>Ext.define('EventReactor', {
      extend: 'Ext.panel.Panel',
      onSomething: function(data) {
          // ERROR
          // this.collapse is undefined. "this" actually references EventTriggerer
          this.collapse();
      }
  });
  
  Ext.define('EventTriggerer', {
      extend: 'Ext.util.Observable',
      singleton: true,
      constructor: function() {
          this.addEvents({
          "changedView" : true
      });
  },
  doSomething: function() {
      // Do some stuff
      this.fireEvent("doneSomething", data);
      }
  });
  
  ...
  
  // Here's how the listeners are added
  var er = Ext.create('EventReactor');
  EventTriggerer.addListener("doneSomething", er.onSomething);
  
  // Here's how the event is triggered.
  er.doSomething();
  </code></pre>