Skip to content

Instantly share code, notes, and snippets.

@ristaa
Created February 8, 2019 13:44
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 ristaa/198c96e346b2c631936eee6be4374a30 to your computer and use it in GitHub Desktop.
Save ristaa/198c96e346b2c631936eee6be4374a30 to your computer and use it in GitHub Desktop.
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