Skip to content

Instantly share code, notes, and snippets.

@fael
Created October 13, 2011 16:50
Show Gist options
  • Save fael/1284764 to your computer and use it in GitHub Desktop.
Save fael/1284764 to your computer and use it in GitHub Desktop.
Exemplo de um Revealing Module Pattern
var revealingModulePattern = function() {
var privateVar = 1;
function privateFunction() {
alert('private');
};
var publicVar = 2;
function publicFunction() {
anotherPublicFunction();
};
function anotherPublicFunction() {
privateFunction();
};
function getCurrentState() {
return 2;
};
// reveal all things private by assigning public pointers
return {
init: publicFunction,
count: publicVar,
increase: anotherPublicFunction,
current: getCurrentState()
}
}();
alert(revealingModulePattern.current)
// => 2
revealingModulePattern.init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment