> module JSON = load 'http://json.org/modules/json2.js'; > > 1) Does - or must - the file json2.js contain only a single top level > module declaration: > > module JSON { > ...source... > }
No. The file json2.js contains the *body* of the JSON module. It can declare as many modules, variables, and functions as it likes. This is less brittle (doesn't require careful coordination between client and library), and crucially it gives the client control over module naming, so that if two vendors produce a module called SuperWidgets, then the client can do: module Acme = "http://acme.com/superwidgets.js"; module Haxx0rz = "http://haxx0rz.com/superwidgets.js"; import Acme.SuperWidgets.foo; import Haxx0rz.SuperWidgets.bar; // ... It's also more convenient for library writers, who don't have to wrap their entire top-level source file with an annoying boilerplate module declaration. > 2) If so, is the load statement equivalent to: > > <script type="harmony" src="http://json.org/modules/json2.js"></script> > > Apart from: > - The script tag will make the module globally available to subsequent > script tags. Whereas, the load form makes the module available only > within the script tag load is called from. > - the load form can parallelize the fetching and compilation of source > more efficiently. That's mostly true, except for the fact that the <script> tag doesn't wrap the contents in a module. Thanks for bringing this up, it's a good point. It might suggest an extra HTML attribute to go that last step: <script type="harmony" module="JSON" src="http://json.org/modules/json2.js"></script> (Which is of course, out of our jurisdiction to specify here, but coordination with other web standards will at some point be necessary, and it's helpful to have at least plausible recommendations.) However, I believe it should also still be possible for browsers to prefetch and parallelize the compilation of source from within module declarations with MRL's, too. This is something we need to experiment with in real implementations, though. Dave _______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss