Javascript provides the global context via the 'windows' or 'globalThis' object:
var a = 10;
function f(s){console.log(s)}
globalThis["f"]("Hallo Welt")
console.log(globalThis.a);
console.log(globalThis["a"]);
Is there a similar thing inside ES6-modules? Referring to the MDN WEB DOCS, If the source is loaded as a module (for HTML, this means adding type="module" to the tag), this is always undefined at the top level.
It seems, this was done intentionally, but maybe there is a workaround? As the module context is encapsulated, flooding the context with definitions seems to be less risky than flooding the global context.
Here is an example:
import * as library from "./library.js"
Object.assign(globalThis, library) // -> expose all exports to the global Namespace
The result is the same as a named import, just you do not need to define import and export synchronously.
I would love to do the same with modules inside a module, just it does not seem to be possible.