I'm trying to implement the modular pattern:
var mod1, mod2;
mod1 = (function (mod2) {
var obj = {};
obj.whichMod = function () {
mod2.whichMod();
};
return obj;
}(mod2));
mod2 = (function (mod1) {
var obj = {};
obj.whichMod = function () {
console.log('mod2');
}
return obj;
}(mod1));
mod1.whichMod();
When I call mod1.whichMod() method, it says mod2 is not undefined. Why is this?
I want mod1.whichMod() to call mod2.whichMod() but mod2 should be "defined" after mod1 like shown above.