I have seen the following code
var MODULE = (function () {
var my = {},
privateVariable = 1;
function privateMethod() {
// ...
}
my.moduleProperty = 1;
my.moduleMethod = function () {
// ...
};
return my;
}());
the properties can be accessed like MODULE.moduleProperty …right?
But how to access globals privateVariable and privateMethod() inside the module(which are globals insode the module …right?)
You can only access them from WITHIN the module code itself as such:
Doing this:
Will call private method (and alert ‘this is private!’) and return the value of privateVariable.
There is no way to access privateVariable or privateMethod outside the MODULE scope.
Hopefully that helps clear it up for you.