I have many modules that are getting loaded depending on the request. I need a global variable that is limited to that connection, not the global scope of the entire code base.
Here is some sample code from Main Module.
var MainModule = function() {
// Do something fun
}
MainModule.prototype.Request = function() {
// Do more fun things
var Mod = require('./MyModule');
var MyModule = new Mod(this);
}
module.exports = MainModule;
.
var MyModule = function(MainModule) {
// Make MainModule Global ??
this.MainModule = MainModule;
}
MyModule.prototype.Foo = function() {
AnotherFunction('321312',function() {
// Need MainModule in this callback
}
}
module.exports = MyModule;
I want this
from MainModule to be global in MyModule as another name of course. The only way I have found to handle this is to create this.MyModule
but that gets cumbersome on each module and more cumbersome when there are many sub modules.
Is there a clean way to handle getting a variable that can be Global in the scope for a module?