I have 2 Javascript files, a main.js
which loads first and then a secondary.js
which loads afterwards. What I am trying to do is create a global function in main.js
which can be utilized on the pages where secondary.js
is loaded.
Here's what I have in main.js
:
var doSomething;
doSomething = function() {
//things to do
}
And then in my secondary.js
:
var result = doSomething();
However, this is returning doSomething is not defined
. I searched SO and found similar questions but was not able to find a solution that worked for me.