+ 1
Global objects in JavaScript
I have a HTML file and some js files. I created an objetc in one of these js files. The object is accessible from the HTMl file, but not from other js files. How can I make an object global?
3 Respostas
+ 7
What do you mean? Can you show your code?
try removing var, let, const which are used to declare local variables instead of global.
Also, make sure other scripts have loaded first before execution.
+ 5
If you remove var, the variable you create will be global (on page) and won't only exist inside the imported script itself. This way scripts will be able to access vars of other scripts.
0
Ok, the script is loaded first in the html document and it starts immediately. And what do you mean with remove var? Isn't it a wrong js command?