Waiting on JS class load from dynamic script loading
<p>I have a JS script which depends on jQuery.</p>

<p>I want to check for jQuery, and if it is not loaded/available add it myself, wait for it to load, and then define my script class.</p>

<p>The code I currently use:</p>

<pre><code>// load jQuery if not loaded yet
if (typeof (jQuery) == 'undefined') {
  var fileref = document.createElement('script');
  fileref.setAttribute("type", "text/javascript");
  fileref.setAttribute("src", 'http://code.jquery.com/jquery-1.4.4.min.js');
  document.getElementsByTagName('body')[0].appendChild(fileref);

  (ready = function() {
    if ( typeof (jQuery) == 'undefined' || !jQuery) {
      return setTimeout( ready, 1 );
    } else {
      // jQuery loaded and ready
      jQuery.noConflict();
    }
  })();
}

// … class definition follows
var MView = function() …
</code></pre>

<p>Now, with FireFox 4 (I think it did work before, or execution was just too slow), it will continue the scripts execution even when I still want to wait on jQuery. The recursive setTimeout is non-blocking.</p>

<p>How can I fix this? Make setTimeout blocking? Use another approach? Is there a better way? A way at all?</p>

<p>The class should be global scope, so it can be used on the page that includes this script file.</p>
