Dynamically loading JavaScript synchronously
<p>I'm using the <a href="http://yuiblog.com/blog/2007/06/12/module-pattern/">module pattern</a>, one of the things I want to do is dynamically include an external JavaScript file, execute the file, and then use the functions/variables in the file in the <code>return { }</code> of my module.</p>

<p>I can't figure out how to do this easily.  Are there any standard ways of performing a pseudo synchronous external script load?</p>

<pre><code>function myModule() {
    var tag = document.createElement("script");
    tag.type = "text/javascript";
    tag.src = "http://some/script.js";
    document.getElementsByTagName('head')[0].appendChild(tag);

    //something should go here to ensure file is loaded before return is executed

    return {
        external: externalVariable 
    }
}
</code></pre>
