It seems that using the following javascript module pattern, it is not possible to have mutually dependent modules:
var AA = (function(module, BB){
module.sayHello = function(){
alert("AA: hello!");
};
module.pokeYourFriend = function(){
BB.sayHello();
};
return module;
})(AA || {}, BB);
var BB = (function(module, AA){
module.sayHello = function(){
alert("BB: hello!");
};
module.pokeYourFriend = function(){
AA.sayHello();
};
return module;
})(BB || {}, AA);
> AA.pokeYourFriend();
*TypeError: Cannot call method 'sayHello' of undefined*
the above fails because BB does not exist at the time AA is created.
is there a pattern that allows this, or should mutual dependency be forbidden?