I have a module script, in which I import some classes and initialize my app. But module scipts declare var myVar = "my"; in module context, what makes init variables unaccessible to main app code. But I don't know how to declare global variable in module script.
-
Possible duplicate of Define global variable in a JavaScript functionObsidian Age– Obsidian Age2018-02-04 19:17:22 +00:00Commented Feb 4, 2018 at 19:17
-
3@ObsidianAge - That answer does not answer in the context of modules which this question is about so that is not a duplicate of this.jfriend00– jfriend002018-02-04 19:19:14 +00:00Commented Feb 4, 2018 at 19:19
-
In modules, you probably should NOT be using a global variable. That's part of the reason for the module design in the first place. You should be exporting and importing variables that you wish to share.jfriend00– jfriend002018-02-04 19:20:13 +00:00Commented Feb 4, 2018 at 19:20
-
You'd have to show us the relevant code and tell us what environment you're running it in for us to offer you options. What you're describing is just learning how to properly design and code with modules (which you might want to do some more reading about). It requires the appropriate structuring of the code and the right imports and exports.jfriend00– jfriend002018-02-04 20:04:50 +00:00Commented Feb 4, 2018 at 20:04
Add a comment
|