title: Javascript saving variable through a scope when using XMLHttpRequest
body: <pre><code>var mapFile = new XMLHttpRequest();
  mapFile.open("GET", "http://localhost:8000/res/map01.txt", true);
  
  mapFile.onreadystatechange = function() {
    if (mapFile.readyState === 4) {
      if (mapFile.status === 200) {
        this.lines = mapFile.responseText.split("\n");
      }
    }
  }
  
  this.lines = mapFile.onreadystatechange.lines;
  
  mapFile.send(null);
  </code></pre>
  
  <p>I have that code and I'm trying to save <code>this.lines</code> inside <code>mapFile.onreadstatechange</code> to later save as <code>this.lines</code> on the outer scope. However, <code>mapFile.onreadystatachange.lines</code> is undefined and I can't save the variable for later use. I even tried using <code>element.innerHTML</code> which is a dirty hack for this but it also didn't work.</p>