title: Variables inside functions + callbacks
body: <p>I have a function (zReaderRequest, see below) where a callback function is using a variable that is local to this first function, i.e. "rq" here. Will new calls to the function zReaderRequest create a new variable "rq" or will the callback functions use the same "rq"? If they use the same, what can I do? Create an object that holds this function, or?</p>
  
  <pre><code>function zReaderRequest(zURL, outputElt, displayFun) {
      switch (outputElt.dataset.zReaderStatus) {
      case undefined:
          outputElt.dataset.zReaderStatus = "requested";
          var rq = new XMLHttpRequest();
          rq.onload = function() {
              if (displayFun(rq, outputElt))
                  outputElt.dataset.zReaderStatus = "received";
              else
                  outputElt.dataset.zReaderStatus = "failed";
          };
          rq.open("GET", zURL, true);
          rq.setRequestHeader("Zotero-API-Version", "2");
          rq.send();
          break;
      }
  }
  </code></pre>
  
  <p>Where do I learn this so I do not have to ask questions like this one? ;-)</p>