title: how to invoke a dynamically loaded javascript function
body: <p>I was implementing a on-demand script controller based on jquery's getscript, it looks like this:</p>
  
  <pre><code>function controller = function(){
  
     var script = function(){
        var scripts = {};
        return {
          load: function(jsurl){
            $.getScript(jsurl, null);
          },
          run: function(js){
            window[js].apply(this,null);
          }
        }
     };
  
    return {
      script: script()
    };
  
  }
  
  var ctlr = controller();
  </code></pre>
  
  <p>then here is a remote script with a function to be loaded - remote.js</p>
  
  <pre><code>function remotefunc(){
    alert( 'remotefunc invoked' );
  }
  </code></pre>
  
  <p>and here is how the whole thing supposed to work, in the main script:</p>
  
  <pre><code>ctlr.script.load( 'remote.js' ); // remote script successfully loaded
  ctlr.script.run( 'remotefunc' ); // got an error, window['remotefunc'] undefined
  </code></pre>
  
  <p>but as you can see, 'remotefunc' is defined in the global 'window' scope, so the window object is supposed to be able to 'see' it. </p>
  
  <p>I thought the problem was probably the closure stuff in the 'controller' definition, so I did a direct $.getScirpt without using the 'controller':</p>
  
  <pre><code>$.getScript( 'http://path/to/remote.js', function(){
    window['remotefunc'].apply( this, null );  // this worked
  } );
  </code></pre>
  
  <p>strange. So it is about the 'controller' implementation(I kind need it)! Anybody can help me out with this? How to fix the 'controller' implementation so the </p>
  
  <pre><code> window[js].apply(this,null);
  </code></pre>
  
  <p>can actually work?</p>
  
  <p>Thanx.</p>