title: Why can't I set a variable equal to an XMLHttpRequest's responseText value?
body: <p>If I am within my XHR's onreadystatechange function, I can easily do <code>document.title = xhr.responseText</code>, but if I make the function return the responseText, I can't set a variable equal to my XHR's outerlying wrapper to make it equal the response; is there any way to go about doing this?</p>
  
  <p>My wrapper:</p>
  
  <pre><code>ajax = function(url, cb)
   {
      xhr = (window.XMLHttpRequest)
          ? new XMLHttpRequest()
          : new ActiveXObject('Microsoft.XMLHTTP');
      xhr.onreadystatechange = function()
       {
          if (xhr.readyState == 4 &amp;&amp; xhr.status == 200)
           {
              cb(xhr.responseText);
           };
       }
      xhr.open('get', url, true);
      xhr.send();
   };
  </code></pre>
  
  <p>Now, if I did something like:</p>
  
  <pre><code>ajax('bacon.txt', function(_)
   {
      document.title = _;
   }
  </code></pre>
  
  <p>it works absolutely perfectly; document.title does in fact become the responseText of the call to bacon.txt. If, however, I try to implement it this way:</p>
  
  <pre><code>document.title = ajax('bacon.txt', function(_)
   {
      return _;
   }
  </code></pre>
  
  <p>no such luck. Can anybody clarify as to why this is?
       };</p>