I am currently transitioning a script I made in Node.js to Electron. However, I am encountering a problem with variable scope. Variables defined in my Node.js script are not available in my modules unless they are passed or assigned. However, in electron if I declare a variable it will be available in all of my modules without passing or assigning it. For example this Node.js script will correctly fail:
// index.js
var myModule = require('./src/myModule.js');
var myString = 'string';
myModule.run();
// myModule.js
exports.run = function() {
console.log(myString); // Correctly says myString is undefined because it is not declared in myModule.js
}
However, the same code in Electron will print the variable defined in renderer.js:
// renderer.js
var myModule = require('./src/myModule.js');
var myString = 'string';
myModule.run();
// myModule.js
exports.run = function() {
console.log(myString); // Prints 'string' even though it is not declared in myModule.js
}
How can I prevent the variables defined in renderer.js from being available in my modules. I find it makes it very easy for me to create unorganized code.