title: Custom Javascript EventManager - please help me complete
body: <p>I am trying to create a custom javascript EventManager class. I've adopted the format Grant Skinner uses in his easel.js framework for creating the class and need to stick with it.  I'm really just lost at this point - I think that - at least in a conceptual sense - I have the right idea here and that it's mostly scope issues that evade me.</p>
  
  <p>I'm hoping someone here can help me take this to the point where addListener and dispatchEvent are functional.</p>
  
  <pre><code>[code]
  
  (function(window) {
      var EventManager = function() {
          this.initialize();
      }
      var p = EventManager.prototype;
  
      // place properties here
  
  
  
      // Constructor
      p.initialize = function() {
          p.listeners = new Array();
      }
  
      // public methods
  
  
      p.addListener = function(fn, event) {
          console.log("p.addListener Hit");
          console.log("event: " + event);
          console.log("handler function: " + fn);
          if(!this.listeners[event]) {
              this.listeners[event] = [];
          }
  
          if(fn instanceof Function) {
              this.listeners[event].push(fn);
          }
          return this;
      }
  
      p.dispatchEvent = function(event, params) {
          console.log("Dispatch Event");
          // loop through listeners array
          for(var index = 0; index &lt; listeners[ev].length; index++) {
              // execute matching 'event' - loop through all indices and
              // when ev is found, execute
              listeners[event][index].apply(window, params);
          }
      }
  
      p.removeListener = function(event, fn) {
          // split array 1 item after our listener
          // shorten to remove it
          // join the two arrays back together
  
      }
      window.EventManager = EventManager;
  
  }(window));
  
  
  [/code]
  [code]
      &lt;script&gt;
  
      eventManager = new EventManager();
  
      var FooTest = function() {
          this.fire = function() {
             //alert("fire");
          }
  
              this.fire();
       };
  
      function onFire() {
         // console.log("FIRED!");
      }
  
      var o = new FooTest();
     eventManager.addListener.call("fire", onFire );
     // eventManager.dispatchEvent.call(o,'fire' );
  
      &lt;/script&gt;
  [/code]
  </code></pre>