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("http://www.public_script.com/well_known_public_script.js")
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:
https://github.com/Ayms/node-gadgets/blob/master/lib/gadgets.js , 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,params.search?params.search:false,ew,params.nbmax?params.nbmax: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 System.download(url) ?
Note : the above case is the exact real life representation of what I am
trying to describe here : https://gist.github.com/2995641
Le 03/07/2012 21:06, Jason Orendorff a écrit :
On Tue, Jul 3, 2012 at 2:29 AM, Aymeric Vitte <[email protected]
<mailto:[email protected]>> wrote:
why can't we have in the module proposal (or somewhere) just the
possibility to load code and eval it (in browsers and server side
environments) ? ie why should I be obliged to transform my script
into a module and have to maintain both, or more if I want to
insure perfect compatibility ? The question is trivial and not
entirely related to modules or ES but since modules are
considered, why not adding this possibility now ?
Well, under the current proposal, you can say:
System.load(url, function () {}, function () {});
This will basically just load the given url and run it,
asynchronously. (The code is treated as a module, but IIUC the only
difference that makes is that global variables and functions it
defines won't pollute the global environment by default -- which seems
like a good thing.)
-j
--
jCore
Email : [email protected]
Web : www.jcore.fr
Webble : www.webble.it
Extract Widget Mobile : www.extractwidget.com
BlimpMe! : www.blimpme.com
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss