2021年3月17日星期三

Import JS file to make its variables part of the global scope of file that is importing them?

So I have a js file (1) filled with variables and I want to import all the variables from the file (1) to another js file (2), for organization purposes, so that these variables make part of the global scope of the js file (2).

I tried "import/export * from [path]" with no success. I can import individual files with the export/import but then I have to call it with "importName.variable" which ends up making the process more complicated with more variables.

I know I could just add the script files to the html as tags and I would get the desired results, but are there any downsides to putting the script files on the html instead of importing them from the js files? Is this the only way of doing what I want?

Thanks in advance.

https://stackoverflow.com/questions/66683758/import-js-file-to-make-its-variables-part-of-the-global-scope-of-file-that-is-im March 18, 2021 at 10:02AM

没有评论:

发表评论