Standard modules - concept or concrete?

Domenic Denicola domenic at domenicdenicola.com
Tue Jun 18 20:29:06 PDT 2013


From: Sam Tobin-Hochstadt


> This is close, but not quite right.  The rule is that any unbound variables in modules are errors.  The variables may be bound by import declarations, or by lexical bindings such as `var` or `let`, or by bindings on the global object, or by top-level `let` bindings (which are not on the global object, IIRC).

Is this correct then?

```js
Date.now();
```

is checked at compile time and found to be OK, because it is referencing a binding that is a property of the global object that exists at the time of static-checking. But

```js
setTimeout(() =>
    asdf(); // (A)
}, 5000);

setTimeout(() =>
    window.asdf = () =>; // (B)
}, 1000);
```

is checked at compile time and found to *error*, because (A) is referencing a binding that is a not a property of the global object at the time of static checking? (Assuming an `asdf` binding is not introduced through any of the other mechanisms you mention.) And this is true even though (B) adds such a property to the global object before (A) ever runs?


More information about the es-discuss mailing list