I would like to use an external javascript file in another javascript file. For example, I could store all my global variablesin a globals.js file and then call then from the website logic logic.js. Then in the index.html, i would insert the tag.How do I use the globals.js inside the logic.js?
Stackoverflow Answer
Javascript doesn't have any implicit "include this other file" mechanisms, like css's @include. You just have to list yourglobals file before the logic file in the tags:
script type="text/javascript" src="globals.js"
If guaranteeing that the globals are available before anything in the logic file fires up, you can do a slow polling loopto see if some particular variable is available before calling an init() or whatever function.