The first goal listed for ecmascript modules: - Obviate need for globals
(http://wiki.ecmascript.org/doku.php?id=harmony:modules). Ironically, the current proposal for module loading includes a global "System" and possibly "Loader". Worse, it seems like the global System is explicitly expected to be mutated. Just in case the not-global is goal is controversial, consider the following code snippets: 1. Using Globals: System.import('./myGreatModule'); 2. Using Modules: import System from './MyCustomLoader'; System.import('./myGreatModule'); Which of these snippets provide a direct path to look for sources of error? In the first one, you need to examine the entire program, and more over you need to carefully consider whether order of execution may alter the outcome. Any code that runs before the snippet, including code delayed by network loading, can change the meaning of System. Such changes could make perfect sense within one set of modules but become an error when those modules are loaded in the same environment as another set. By contrast, the second snippet directs your attention to a single file. Let's look into what a custom loader module might look like: import {SystemLoader, SystemLoaderHooks} from 'System'; // immutable Loader class class Loader extends SystemLoader { constructor() { super(SystemLoaderHooks); } // override, delegate, reuse SystemLoader API // add non-standard custom functions } export var System = new Loader(); (Here I have used the capital variable System to emulate the module loader discussion. Personally I think the package should be named 'system' and developers should be using systemLoader.import().) As a bonus, modular Loader would provide more incentive for developers to adopt modules since they cannot use dynamic loading without also using modules. The only downside I see to a modular Loader is that simple demo code will require two files. I hope someone will offer a stronger case for our mutable global Loader. jjb
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss