title: Maintain scope when loading script with jQuery
body: <p>Say I have a file 'test.js' with the following contents:</p>
  
  <pre><code>var test = 'something';
  </code></pre>
  
  <p>Then I have a primary script that needs to load up test.js to grab the test variable.</p>
  
  <p>Obviously this works:</p>
  
  <pre><code>$.ajax({dataType: "script", cache: true, url: 'test.js'});
  </code></pre>
  
  <p>The issue is that the variable <code>test</code> exists in the global scope. I'm curious if there's a way to add it into an object and keep it out of the global scope.</p>
  
  <p>Something like:</p>
  
  <pre><code>function scriptloader() {
      this.grabscript = function() {
          return $.ajax({dataType: "script", cache: true, url: 'test.js'});
      }
  }
  
  var myloader = new scriptloader();
  
  myloader.grabscript();
  </code></pre>
  
  <p>Where ideally myloader would contain the loaded variable <code>test</code>. However, I can console.log(test) and still see 'something'.</p>
  
  <p>Is there a way to lock the loaded script into scope or am I dreaming?</p>