I'm currently diving into the world of structures and anonymous functions in JavaScript, and after examining various codes and libraries that implement this technique, I decided to give it a shot. However, when attempting to replicate the method they used, I seem to be running into issues with calling the wrong initialization function. Let's take a look at my code:
File 1: startUp;
this.project = this.project || {};
(function(){
project.init = function (){
console.log("startUp");
project.Setup();
}
}());
File 2: Setup
this.project = this.project || {};
(function() {
var Setup = function() {
this.init();
};
var p = Setup.prototype;
p.init = function() {
console.log("Setup");
};
project.Setup = Setup;
}());
For some reason, the init function in the Setup file isn't being called, while the startUp init function is stuck in an infinite loop.