title: How to add callback function to a javascript class?
body: <p>The following code in javascript gives me the error <em>"this.callback is not a function</em></p>
  
  <pre><code>function ajaxRequest()
  {
      var httpObject;
  
      this.open = open;
      this.callback = function(){};
  
      function getHTTPObject()
      {
          if (window.ActiveXObject) 
              return new ActiveXObject("Microsoft.XMLHTTP");
          else if (window.XMLHttpRequest)
              return new XMLHttpRequest();
          else 
          {
              alert("Your browser does not support AJAX.");
              return null;
          }
      }
  
      function onstatechange()
      {
          if(httpObject.readyState == 4)
          {
              this.callback(httpObject.responseText);
          }
  
      }
  
  
      function open(url, callback)
      {
          httpObject = getHTTPObject();
          if (httpObject != null) 
          {
              httpObject.open("GET", url, true);
              httpObject.send(null);
              this.callback = callback;
              httpObject.onreadystatechange = onstatechange;
          }
      }
  }
  </code></pre>
  
  <p>why doesn't open method treat the callback parameter as function?</p>
  
  <p>If it does then why can't i call it in onstatechange function?</p>
  
  <p>How do i make this work?</p>