title: How can I access variable from a concatenated script that holds another script inside it?
body: <p>I have this code to open a file in NW.JS.</p>
  
  <pre><code>function chooseFile(name, handleFile) {
      var chooser = document.querySelector(name);
      chooser.addEventListener("change", function(evt) {
          for(var f of this.files){
              console.log(f.name);
              console.log(f.path);
              handleFile(f.name, f.path);
          }
      }, false);
  
      chooser.click();  
  }
  chooseFile('#fileDialog', function(name, path){ ... /* do something with the file(s) */ });
  </code></pre>
  
  <p>I have concatenated that code into a string so that I can inject it into a div (when that div is created) from a button click that generates the above code with unique id’s thusly..</p>
  
  <pre><code>var letsDoThis = '$(".' + imgUploadClass + '").click(function(){ var leid = this.id; var theEditId = "divId" + leid.slice(5); function ' + imgUploadChoose + '(name, handleFile) { var chooser = document.querySelector(name);chooser.addEventListener("change", function(evt) { for(var f of this.files){console.log(f.name);console.log(f.path);handleFile(f.name, f.path);}}, false);chooser.click();}' + imgUploadChoose + '("#' + imgUploadzz +'", function(name, path){' + 'alert(path);' + ';});});';
  </code></pre>
  
  <p>When testing I can access the name and path inside the alert box! GREAT! The code I want to run where </p>
  
  <pre><code>'alert("Hello!");’
  </code></pre>
  
  <p>is needs to be the following (but instead of a hardcoded url I need to access “path” from the (uniquely named) chooseFile script)...</p>
  
  <pre><code>'$("#" +' + 'theEditId).css("background-image", "url(http://www.jqueryscript.net/images/Simplest-Responsive-jQuery-Image-Lightbox-Plugin-simple-lightbox.jpg)");'
  </code></pre>
  
  <p>I am pretty sure I am not escaping a comma or something, here is another piece of code I got to fire correctly but not being able to access “path”...</p>
  
  <pre><code>'$("#" +' + 'theEditId).css("background-color", "green");'
  </code></pre>