Losing this context inside a closure (module)
The use of $.each causes this context to change back to the global context (window). Despite efforts, like using self, calling sub functions always revert the context thereafter.
HTML
<pre id='log'></pre>
CSS
body {
font-family: verdana, Arial, sans-serif;
}
JavaScript
var MyModule = (function ($) {
var self = {};
var privateFunction = function () {
console.log(self);
}
self.init = function () {
privateFunction(); // exposes all the public methods of self, keeping the "private" functions private
};
return self;
}(jQuery));
MyModule.init();