Created
November 10, 2017 10:56
-
-
Save unflores/35d3122954774ff01e4eba64e4f3f27d to your computer and use it in GitHub Desktop.
Once a singleton always a singleton
This file contains hidden or 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 Thing = require('./thing'); | |
console.log('Include thing from another file'); | |
console.log(Thing.thing, ":thing in included"); |
This file contains hidden or 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 Thing = require('./thing'); | |
console.log(Thing.thing, ": thing in main"); | |
Thing.setSomething(); | |
console.log(Thing.thing, ":thing in main"); | |
require('./included'); |
This file contains hidden or 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
// Thing.thing gets cached after the first require | |
// As long as the data is set early on, all subsequent requires | |
// will have access to it. | |
module.exports = { | |
setSomething: function() { | |
console.log('set Thing.thing'); | |
module.exports.thing = 5; | |
}, | |
thing: undefined | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment