For the module pattern, I\'m doing something like:
(function(namespace) {
// tons of code
// blabla
})(window.myGlobalNamespace);
H
It sounds like what you're after is Require JS. I use this in almost all of my builds now. Alternatively you can have a look at the revealing module pattern as a fallback but for what you're after it sounds like Require is much more suitable.
http://requirejs.org
A good read: http://net.tutsplus.com/tutorials/javascript-ajax/principles-of-maintainable-javascript/