After dynamically loading a module, i.e. after the corresponding promise has been resolved, one can act with a function or lambda-expression on the result. I was surprised to find that the module-instance (provided by the promise) does not have a prototype:
import("./module.js").then(x => {
console.log(typeof x); // yields 'object' as expected
console.log(x instanceof Object); // yields false !!
console.log(x.__proto__); // yields undefined !!
console.log(Object.getPrototypeOf(x)); // yields null !!
// but one can certainly access exported variables / functions
x.exportedFunction();
})
Apparently, in spite of being an 'object', x
does not seem to be an Object
instance and does not seem to have any prototype at all. I wasn't aware that this is even possible. Firefox/Chrome and Safari all gave the same output (the one I spelled out in the code-comments). Is there an explanation? Is this specified anywhere? What kind of object is this module x
?
Note: I'm not familiar with typescript, so I'm not sure if my question could be considered a duplicate of this one
Edit: I just realized that one obtains the same weird pseudo-object for statically imported modules into a namespace or module object via import * as x from "./module.js"
. Although MDN mentions these objects they don't elaborate on what they are.