Managing my application's 2000 lines of javascript code can be challenging, especially with all the user interaction and jQuery elements. Fortunately, everything is functioning as it should :)
To make things more organized, I decided to split the code into five separate files.
I initially thought that loading all the files would enable them to communicate and share variables in memory. However, I encountered an issue where a variable defined in File A was not recognized in File B.
Additionally, I have some general scripts in File C that I hoped Files A and B could utilize, but it seems this may not be possible.
Any advice on how to address these issues would be greatly appreciated.
UPDATE
The structure of my javascript looks like this:
// FILE A
jQuery(document).ready(function() {
var currentPage = getURLvar('slpage');
if ( (currentPage == 'Aa') || (currentPage == 'Bb') ) {
init_AA();
}
else if ( (currentPage == 'Cc') || (currentPage == 'Dd') ) {
init_BB();
} else if ( (currentPage == 'Ee') || (currentPage == 'Ff') ) {
init_CC();
}
(...)
// FILE B
function init_AA()
{
(...)
}
function getURLvar(name)
{
//Gets the URL and returns the value of specified paramter.
}