I’ve several JS files; the first one is a library to be used by the next ones, and every one of those another files have a function main() which calls the functions of that file.
lib.js => library
a.js :: main() => call functions in a.js
b.js :: main() => call functions in b.js
…
…
So, I would want that were run the function main for those files (after of loading lib.js).
How do run each function main after of loading the JS file?
It would be load a.js and run main, load b.js and run main, …
JavaScript is not C or something similar.
It doesn’t matter in which file you define the function. The function will be overwritten.
So if you first load the file
a.jsand then the fileb.jsThemainfunction will be themainfunction which you’ve defined inb.jsand themainfunction you’ve defined ina.jswon’t exists anywhere.If you want to keep old functions I recommend you to create an object in each file and define the main function in it. So something like this.
a.js:b.js:So now you can call:
and