title: XMLHttpRequest inside an object: how to keep the reference to "this"
body: <p>I make some Ajax calls from inside a javascript object.:</p>
  
  <pre><code>myObject.prototye = {
    ajax: function() {
      this.foo = 1;
  
      var req = new XMLHttpRequest();
      req.open('GET', url, true);
      req.onreadystatechange = function (aEvt) {  
        if (req.readyState == 4) {  
          if(req.status == 200)  {
            alert(this.foo); // reference to this is lost
          }
        }
    }
  };
  </code></pre>
  
  <p>Inside the onreadystatechange function, this does not refer to the main object anymore, so I don't have access to this.foo. Ho can I keep the reference to the main object inside XMLHttpRequest events?</p>