External and internal modules

Dmitry Soshnikov dmitry.soshnikov at gmail.com
Mon Sep 9 00:33:06 PDT 2013


Hi,

Couple of questions on current modules system (as I see, they are not part of recent ES6 draft, the only thing which exists is this wiki article: http://wiki.ecmascript.org/doku.php?id=harmony%3Amodules).

1. By prediction and observing of current situation with "require" modules system, 90% of modules will be external modules, that is live in separate files, which contain module bodies directly.

2. As I understand, this `module "foo" { ... }` way of defining is either for inner modules (inside a parent external modules), or inside an external file which is not a module, but a script (and therefore, cannot be loaded as module).

The first case isn't that useful -- I defined an inner module inside a parent external module, and then what? -- import it exactly in the same file? What is that mean? Naming collisions happen not that often inside a module (this is why it's a module), that sub-devide it on sub-modules.

Or can I probably export this inner submodule from the parent? How this double import will look like, if it's even possible? First import the inner module form the parent, then bindings from the inner?

If the parent file is not actually a module, but a script -- how this script is loaded? On the web using <script>? On Node.js? -- using ..."require"? Two module systems?

3. For external modules, will it be possible to omit filename extension? `import foo from "foo.js"` -- sounds obsolete, unless we'll be able to import modules written on different languages.

4. What is export from module?

import {foo} from "foo.js";
export {foo} from "foo.js"

First makes sense to me (well, syntax is debatable, but anyways), the second I don't understand. Can I, as a caller, re-export (i.e. make public) something from not my module, and that was specially not exported?

Thanks,

Dmitry


More information about the es-discuss mailing list