Skip to content

Instantly share code, notes, and snippets.

@user24
Created September 2, 2011 14:06
Show Gist options
  • Save user24/1188669 to your computer and use it in GitHub Desktop.
Save user24/1188669 to your computer and use it in GitHub Desktop.
Revealing Module Pattern
// Define an object using the Revealing Module Pattern
var myCounter = function() {
// Both Private and Public methods and properties are defined here
var counter = 0;
function count() {
return 0+counter;
}
function increment() {
counter++;
}
function decrement() {
counter--;
}
// Return references to those members which you wish to be public.
return {
'increment':increment,
'decrement':decrement,
'count':count
};
}();
// Use the public interface.
myCounter.count(); // 0
myCounter.increment();
myCounter.count(); // 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment