Static Module Resolution

Sam Tobin-Hochstadt samth at
Wed Jul 4 06:39:47 PDT 2012

On Wed, Jul 4, 2012 at 6:12 AM, Aymeric Vitte <vitteaymeric at> wrote:
> This is not exactly what I would like to do, I would like to decide where I
> want to run it and when (whether it's sync or async), the global environment
> can be protected by strict mode now if you don't eval within it.
> Basically I would like to have :
> var code=download(url);      //download("./my_server_secret_script.js")
> //download("")
> eval(code); //sync or asynch
> The problem with the loader proposal is that you need a callback and it only
> extends the global scope, so the loader does not know the surrounding
> environment where it is called, example :
> console.log(global);//global
> var callback=function() {
>     var window=some window; //not a global var
>     System.load('script.js',function() {console.log(res)}; //script.js -->
> var res=window.document.body
>     //crash
> }
> Real example here:
> , section :
> 			window=dom(page,null,options);
> 			document=window.document;
> 				document.onload=function() {
> 					var EWA = require('ewa').EWA;
> 					var ewa = new
> EWA(!!params.gadget,!!params.price,,ew,params.nbmax?params.nbmax:<
> span class="mi">100);
> 'ewa' was a normal script that was transformed into a module (even if on
> server side I could have loaded it and eval it (but with a callback), let's
> consider the same case where I need a public script into the browser), and
> 'window' and 'document' had to become "super" global vars to make it work
> Using System.load I don't have to transform the script into a module but I
> still need to make 'window' and 'document' global vars, and I have now to
> use a callback
> Then why not just a ?

I'm slightly confused about what you want here.

If you just want the ability to download code, and then eval it using
the loader mechanism, that's already there -- just use XHR to get the
code, and then call `System.eval(...)`.

If you want the ability to fetch the source the way that the loader
would do it, and then not actually *load* the code, we could
potentially add that, but it's tricky for recursive cases -- would you
want all the relevant code, or just the specified module?

Or do you want something else than this?

Finally, I don't see why your example doesn't work exactly as:

    document.onload(function() { System.load("ewa.js", ...); })
sam th
samth at

More information about the es-discuss mailing list