title: Javascript - how to reference a callback from string/object
body: <p>This code isn't working since it seems I declared an object with attributes. How to have it working and reference the callback from the string/object I pass?</p>
  
  <pre><code>var HttpDispatcher = function() {
    this.listeners = { get: [ ], post: [ ] }; 
  } 
  
  HttpDispatcher.prototype.on = function(method, url, cb) {
  
    this.listeners[method].push({
      cb: cb,
      url: url 
    }); 
  }
  
  var obj = new HttpDispatcher();
  obj.on("get", "page1", function() {document.write("hello");});
  
  document.write(obj.listeners["get"]["page1"]()); // won't work for "page1"
  </code></pre>