Standard modules - concept or concrete?

Sam Tobin-Hochstadt samth at ccs.neu.edu
Wed Jun 19 08:42:33 PDT 2013


On Wed, Jun 19, 2013 at 11:37 AM, Kevin Smith <zenparsing at gmail.com> wrote:
> OK - I see it on the wiki here:
>
> "Compilation resolves and validates all variable definitions and references"
>
> It still seems odd to me that we're going to check a dynamic object (the
> global object) at link-time for references.  What if the global object is
> changed after the linking pass, but before the module executes?  Does the
> variable reference still point to the old thing?
>
>     // Before linking, window.bar = "before"
>
>     // foo.js
>     bar = "after";
>
>     // main.js
>     import "foo";
>     console.log(bar); // "before"?

This produces "after" -- mutable variables are still mutable.  Saving
an old version would be pretty strange.

Note that there are situations where you can still get a
ReferenceError inside a module, by deleting properties off of
`window`.   Ruling this out would require:

1. not giving modules access to the global scope, or
2. changing the global object when compiling modules

Neither of these seem like good ideas.

Sam


More information about the es-discuss mailing list