I'm still struggling with this. Does *anyone* know where, in the wild, Module Environments (a type of Lexical Environment) exist?https://twitter.com/padolsey/status/1151148086812696576 …
-
-
Replying to @padolsey
ModuleEnvironment is an abstract spec concept. It doesn’t “exist” in implementations in that there is no user-accessible object that directly corresponds to the concept.
1 reply 0 retweets 0 likes -
Replying to @mathias
Am I right to presume that it would "exist" as a true scope (i.e. an accessible lexical environment in which we could declare things) in Node.js if Node didn't do that weird module wrapping thing as per https://nodejs.org/api/modules.html#modules_the_module_wrapper … ?
2 replies 0 retweets 0 likes -
And yep to clarify when I say "exists" I mean in terms of talking about the current scope. Like in normal <script>s you'd say "I'm defining stuff in the global scope", while in Node you'd say "I'm defining stuff in the module scope" (Tho in Node it's really just a func scope...)
1 reply 0 retweets 0 likes -
There's also <script type="module">, but yeah it seems to feel exactly like a function scope.
1 reply 0 retweets 1 like -
-
Replying to @padolsey @jaffathecake
The module scope lives within the global scope. I tried to visualize it here: https://mathiasbynens.be/notes/globalthis#terminology … In Node.js…
a classic script is wrapped and then run in the global scope
a module is wrapped and then run in the module scope2 replies 0 retweets 2 likes -
At least, this is how it works in JS engine binaries that don’t do Node.js-style wrapping. cc
@guybedford@bradleymeck@ljharb@MylesBorins to correct me on the above1 reply 0 retweets 0 likes -
There's also <script>const foo = 'bar'</script> which exists on the global scope but not the global object, right?
1 reply 0 retweets 4 likes -
Replying to @jaffathecake @padolsey and
const/let/class create lexical bindings, so in your example the binding exists in the “top-level lexical scope”, which I see as distinct from the global scope.
2 replies 0 retweets 3 likes
The other side of this is that <script type=module> var foo = 42; </script> doesn’t create http://globalThis.foo , because of the module scope. https://v8.dev/features/modules#intro …
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
JavaScript, HTML, CSS, HTTP, performance, security, Bash, Unicode, i18n, macOS.