Skip to content

Instantly share code, notes, and snippets.

@bradoyler
Created March 11, 2014 13:05
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 bradoyler/9485209 to your computer and use it in GitHub Desktop.
Save bradoyler/9485209 to your computer and use it in GitHub Desktop.
JS lesson: module example #1 - a self-contained module
var testModule = (function () {
var counter = 0;
return {
incrementCounter: function () {
return counter++;
},
resetCounter: function () {
console.log( "counter value prior to reset: " + counter );
counter = 0;
}
};
})();
// Increment our counter
testModule.incrementCounter();
// Check the counter value and reset
// Outputs: 1
testModule.resetCounter();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment