This module is a variation of the classic module pattern in which all variables and functions are defined in the private scope and an anonymous object is returned, with pointers to the private members we want to make public.
var profile = (function(){
//private
var name = "";
function setName(nameStrg){
name = nameStrg;
}
function getName(){
console.log("Name: " + name);
}
function sayHello(){
console.log('Hello ' + name);
}
//public pointers
return{
giveName: setName,
getName: getName,
greet: sayHello
}
})();
-
Allows syntax of scripts to be more consistent.
-
Makes it more clear which members may be accessed publicly.
- Public members can't be overriden by a patch if necessary.