Created
July 10, 2014 21:16
-
-
Save erberg-snippets/08d0684829320e50047c to your computer and use it in GitHub Desktop.
Module pattern in javascript.
This file contains 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 myNamespace = (function () { | |
var myPrivateVar, myPrivateMethod; | |
// A private counter variable | |
myPrivateVar = 0; | |
// A private function which logs any arguments | |
myPrivateMethod = function( foo ) { | |
console.log( foo ); | |
}; | |
return { | |
// A public variable | |
myPublicVar: "foo", | |
// A public function utilizing privates | |
myPublicFunction: function( bar ) { | |
// Increment our private counter | |
myPrivateVar++; | |
// Call our private method using bar | |
myPrivateMethod( bar ); | |
} | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment