I'm trying to improve my javascript and have been using the revealing module pattern to good effect but I noticed that code in the module not in a function or the return is executed on creation have utilised this, such as:
var MyModule = function ($) {
setUp();
function setUp() {
// execute code to be run when module created
}
function doStuff() {
}
return {
doStuff: doStuff
}
}
I can see this is creating a form of constructor for the function which relies on it being called by var myModule = new MyModule(jQuery)
.
Any feedback on the rights or wrongs of this appreciated.