While working on maintainence of a site, I came across this coding pattern being followed for all the javascript files included in the page, which seems like a mix of factory pattern and some other pattern:
var MainFunction = new function() {
var _cntr = 0;
var _sCntr = 0;
var _init = function() {
//main logic & other methods called here
_innterMethod1();
_innterMethod2();
}
var _innerMethod1 = function() {
// innermethod1 logic goes here
}
var _innerMethod2 = function() {
// innermethod2 logic goes here
}
this.tostring = function() {
return "[object MainFunction]";
};
_init.call(this);
};
While it is easy to understand the flow, what is bothering me is what pattern is being followed here? What is the author trying to acheive/gain with this style of coding [ compared to following other more popular patterns to achieve the same functionality?]