Module Pattern
Description
Singletons are objects of which there will only ever be one instance.
The module pattern, as described by Douglas Crockford, augments the basic singleton to allow for private variables and privileged methods, taking the following format:
var singleton = function(){
//private variables and functions
var privateVariable = 10;
function privateFunction(){//from w ww . ja v a2 s . com
return false;
}
//privileged/public methods and properties
return {
publicProperty: true,
publicMethod : function(){
privateVariable++;
return privateFunction();
}
};
}();