What's the value of this
in an imported function, which is called from a namespace import? (according to the ECMA spec)
// module.js
export function fun() {
return this;
}
// main.js
import * as module from "./module.js";
let x = module.fun(); // What's the value of x here?
My guess would be: It's the module
object, but haven't found a clear answer to this in the spec. Does the normal behavior apply here or is there something special in ES6 modules for namespace imports?
No, there is no special behaviour here. Module namespaces may be exotic objects which delegate all accesses to some internals and which are pretty much immutable, but they're still just objects. Method invocations on them don't work different than on any other object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With