Skip to content

Instantly share code, notes, and snippets.

@babjo
Last active August 1, 2021 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save babjo/5c59261a808d61102583a289c5b2c344 to your computer and use it in GitHub Desktop.
Save babjo/5c59261a808d61102583a289c5b2c344 to your computer and use it in GitHub Desktop.
var testModule = (function () {
var myPrivateVar, myPrivateMethod;
// A private variable
myPrivateVar = 0;
// A private function
myPrivateMethod = function(foo) {
console.log(foo);
};
return {
// A public variable
myPublicVar: "foo",
// A public function
myPublicFunction: function(bar) {
// Increment our private counter
myPrivateVar++;
// Call our private method using bar
myPrivateMethod(bar);
}
};
})();
// Usages
testModule.myPublicFunction();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment