title: Adding parameter to anonymous function
body: <p>In PHP, I can bind a variable to a lambda like this:</p>
  
  <pre><code>$locale = "nl_NL";
  $info['t'] = function($text, $render) use ($locale) {
     return translate($text, $locale);
  }
  </code></pre>
  
  <p>In the below code, the <code>fullpath</code> variable gets overwritten and contains the value of the latest call at some point.</p>
  
  <pre><code>var tree = {
      "foo.js": null,
      "bar.js": {
           "baz.js": null
      }
  }
  
  loadScriptTree(tree) {
      for (let idx in tree) {
          var fullpath = "root/" + idx;
          console.log("Loading "+fullpath);
  
          var subtree = tree[idx];            
          $.getScript(fullpath, function() {
              console.log(fullpath+ "loaded.");
              loadScriptTree(subtree);
          });
      }
  }
  </code></pre>
  
  <p>How can I bind the variable to the function in JavaScript? </p>