Created
October 13, 2011 16:50
-
-
Save fael/1284764 to your computer and use it in GitHub Desktop.
Exemplo de um Revealing Module Pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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