title: using getScript to import plugin on page using multiple versions of jQuery
body: <p>I am developing an app on a page that uses jQuery 1.2.6, but I would like to use jQuery 1.4.2 for my app. I really don't like to use multiple versions of jQuery like this but the copy on the page (1.2.6) is something I have no control over. I decided to isolate my code like this:</p>
  
  <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;&lt;head&gt;
  &lt;script type="text/javascript" src="jquery-1.2.6.min.js&gt;
  &lt;script type="text/javascript" src="pageStuff.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  Welcome to our page.
  &lt;div id="app"&gt;
      &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript" src="myStuff.js"&gt;&lt;/script&gt;
  &lt;/div&gt;
  &lt;/body&gt;&lt;/html&gt;
  </code></pre>
  
  <p>The file myStuff.js has my own code that is supposed to use jQuery 1.4.2, and it looks like this:</p>
  
  <pre><code>(function($) {  //wrap everything in function to add ability to use $ var with noConflict
      var jQuery = $;
      //my code
  })(jQuery.noConflict(true));
  </code></pre>
  
  <p>This is an extremely simplified version, but I hope you get the idea of what I did. For a while, everything worked fine. However, I decided to use a jQuery plugin in a separate file. I tested it and it acted funny. After some experimentation, I found out that the plugin was using the old version of jQuery, when I wanted it to use the new version. Does anyone know how to import and run a js file from the context within the function wrapping the code in myStuff.js?</p>
  
  <p>In case this matters to anyone, here is how I know the plugin is using the old version, and what I did to try to solve the problem: I made a file called test.js, consisting of this line:</p>
  
  <pre><code>alert($.fn.jquery);
  </code></pre>
  
  <p>I tried referencing the file in a script tag the way external Javascript is usually included, below myStuff.js, and it came up as 1.2.6, like I expected. I then got rid of that script tag and put this line in myStuff.js:</p>
  
  <pre><code>$.getScript("test.js");
  </code></pre>
  
  <p>and it still came back as 1.2.6. That wasn't a big surprise -- according to <a href="http://api.jquery.com/jQuery.getScript/" rel="nofollow noreferrer">jQuery's documentation</a>, scripts included that way are executed in the global context. I then tried doing this instead:</p>
  
  <pre><code>var testFn = $.proxy($.getScript, this);
  testFn("test.js");
  </code></pre>
  
  <p>and it still came back as 1.2.6. After some tinkering, I found out that the "this" keyword referred to the window, which I assume means the global context. I am looking for something to put in place of "this" to refer to the context of the enclosing function, or some other way to make the code in the file run from the enclosing function. I noticed that if I copy and paste the code, it works fine, but it is a big plugin that is used in many places, and I would prefer not to clutter up my file with their code. I am out of ideas. Does anyone else know how to do this?</p>