Skip to content

Instantly share code, notes, and snippets.

@clouddueling
Created November 14, 2012 15:57
Show Gist options
  • Save clouddueling/4072944 to your computer and use it in GitHub Desktop.
Save clouddueling/4072944 to your computer and use it in GitHub Desktop.
Javascript: The Module Pattern
// Source: http://javascriptweblog.wordpress.com/2010/12/07/namespacing-in-javascript/
var myApp = (function() {
var id= 0;
return {
next: function() {
return id++;
},
reset: function() {
id = 0;
}
};
})();
window.console && console.log(
myApp.next(),
myApp.next(),
myApp.reset(),
myApp.next()
) //0, 1, undefined, 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment