I wonder how to manipulate the global scope of imported file to some object. For example the imported file:
// File A.js
export const str = `hello ${world}`;
function export foo() {
return n1 + n2;
}
Then I want to use an object for the global scope of the imported file, like:
const scope1 = {
world: 'world',
n1: 1,
n2: 2
}
const scope2 = {
world: 'to you',
n1: 100,
n2: 200
}
Then when I import import * as A from 'A'
, the global scope will be taken from the objects scope1
or scope2
(like bind
but to import statement).
Is there an easy way to achieve this behavior?