Created
June 9, 2015 18:08
-
-
Save drewblaisdell/e947369630551c8932a6 to your computer and use it in GitHub Desktop.
Singleton w/ closure
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 drewIsCool = false; | |
module.exports = { | |
isDrewCool: function() { | |
return drewIsCool; | |
}, | |
makeDrewCool: function() { | |
drewIsCool = true; | |
} | |
}; | |
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 drewModule = require( './drewModule' ); | |
console.log( drewModule.isDrewCool() ); // false | |
drewModule.makeDrewCool(); | |
console.log( drewModule.isDrewCool() ); // true | |
var drewModule2 = require( './drewModule' ); | |
console.log( drewModule2.isDrewCool() ); // true | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment