Created
March 11, 2014 13:05
-
-
Save bradoyler/9485209 to your computer and use it in GitHub Desktop.
JS lesson: module example #1 - a self-contained module
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 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