Ok so I have a .js file with about 10k lines of code. This code can be split up in
- sub-object definitions
- container object definitions
- initialization code (after the objects have been defined)
- program functionality
I would like to split this one file into 4 separate files, because it provides a better oversight. How do I go about doing this, given that they absolutely have to be declared in that order? What should I wrap up in a $(document).ready() and what not?
If I just separate the files and link them to the html in the correct order, I get undefined object errors. I was also thinking of something like this; but I don't know if that's any good...
Second JS File
function initializeContainers() { var containerObj1 = { bla: 'bla', bla2: 'bla2' }, var containerObj2 = { bla: 'bla', bla2: 'bla2' }; }; First JS File
$(document).ready(function() { function initializeSubObjects(callback) { var subObj1 = { somekey: 'somevalue', someke2: 'someothervalue' }; callback(); }; initializeSubObjects(initializeContainers); }); I have no clue whether this is the correct way to do it? PS: I also know you can add the script tags dynamically; but is that good practice?