Nested modules clarification

David Herman dherman at mozilla.com
Tue Jul 17 23:21:10 PDT 2012


On Jul 17, 2012, at 9:17 PM, ๏̯͡๏ Jasvir Nagra wrote:

> However, Module Semantics (http://wiki.ecmascript.org/doku.php?id=harmony:modules_semantics) suggests that each inline module declaration introduces a fresh scope.

As in, a fresh *nested* scope.

> Given this, I am trying to understand whether there is any difference in semantics between nested rather than sibling modules.

Yes. They can refer to outer bindings.

> For example, is there any semantic difference between the following:
> module widgets {
>     export module button { ... }
>     export module alert { ... }
>     export module textarea { ... }
>     ...
> }
> import { messageBox, confirmDialog } from widgets.alert;
> and
> module widgets.button { ... }
> module widgets.alert { ... }
> module widgets.textarea { ... }
> ...
>  
> import { messageBox, confirmDialog } from widgets.alert;
> 
> ...other than the change to the grammar that module name can now contain a ".".

Well, you didn't tell us what the semantics of your new syntax is. :) But it seems to suggest that anyone anywhere could add to a module. The declarative syntax is meant to keep the exports of a module local to its body. Allowing anyone anywhere to extend a module runs counter to the idea of modularity.

Dave

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


More information about the es-discuss mailing list