Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Module design pattern in JS
var basketballModule = (function(){
var points = 0;
return {
twoPointsMade: function(){
return points = points + 2;
},
threePointsMade: function(){
return points = points + 3;
}
}
})();
basketballModule.twoPointsMade(); // 2
basketballModule.threePointsMade(); // 5
basketballModule.threePointsMade(); // 8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.