A few more questions about the current module proposal

Andreas Rossberg rossberg at google.com
Fri Jul 6 01:42:54 PDT 2012

On 5 July 2012 19:33, Russell Leggett <russell.leggett at gmail.com> wrote:

> Oh, I also meant to ask - I do have a question of my own. It seems so
> basic, but I can't figure it out. If I have a file that contains two
> modules - let's say in foo.js
> ------- foo.js ----------------
>     module Foo {
>         export let x = 42;
>     }
>     module Bar {
>         export let y = 12;
>     }
> and I try to do:
>     import y from "foo.js"
> What happens? Similar problem if I try to do
>     import "foo.js" as Foo
> Am I incorrect in thinking that there can be more than one top level
> module? Or is it that an imported file is automatically a module, and
> therefore Foo and Bar are nested modules in this case? Would I then have to
> say "export module Foo..." and later "import Foo from "foo.js;"?

Yes, an imported file is a module body by itself, so Foo and Bar are nested
modules. Your first import hence is an error, and the second one binds a
module Foo with members Foo.Foo and Foo.Bar.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120706/eaac3e62/attachment.html>

More information about the es-discuss mailing list