Skip to content

Instantly share code, notes, and snippets.

@tonycaputome
Last active December 20, 2015 19:38
Show Gist options
  • Save tonycaputome/6184254 to your computer and use it in GitHub Desktop.
Save tonycaputome/6184254 to your computer and use it in GitHub Desktop.
var Module = (function(){
//variabili e funzioni private
var foo;
var setFoo = function(val){ foo = val; };
var getFoo = function(){ return foo; };
var increment = function(){
if(!foo){
setFoo(0);
}
foo++;
};
//restituiamo le funzioni che vogliamo rendere pubbliche
return {
increment : increment,
getFoo : getFoo
};
})();
//utilizzo
Module.increment();
console.log("foo = " + Module.getFoo()); //foo = 1
console.log(Module.foo); //undefined
Module.setFoo(5); //TypeError: Module.setFoo is not a function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment