Skip to content

Instantly share code, notes, and snippets.

@Allan-Gong
Created November 15, 2016 13:09
Show Gist options
  • Save Allan-Gong/54453df59e108e6464c2537c4e887184 to your computer and use it in GitHub Desktop.
Save Allan-Gong/54453df59e108e6464c2537c4e887184 to your computer and use it in GitHub Desktop.
Javascript's Revealing Module Pattern by example
var myRevealingModule = (function () {
var privateVar = "Ben Cherry",
publicVar = "Hey there!";
function privateFunction() {
console.log( "Name:" + privateVar );
}
function publicSetName( strName ) {
privateVar = strName;
}
function publicGetName() {
privateFunction();
}
// Reveal public pointers to
// private functions and properties
return {
setName: publicSetName,
greeting: publicVar,
getName: publicGetName
};
})();
myRevealingModule.setName( "Paul Kinlan" );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment