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