This is probably a dumb question but i wanted to clarify this things to my self and get other opinions about it.
Let's say i have a node file x.js
like this.
var x=0;
module.exports = init = function(someValue){
if(someValue)
x=someValue;
}
init.prototype.getX = function(){
return x;
}
And let's say i've y.js
like this.
var X = require('x')(10);
X.getX() //this will return 10 right?
But my question is this, if i have z.js
file with the following content.
var X = require('x')();
//what will x.getX(); returns?
do it return 10, because 10 is set on y.js
file or 0?
In what way should i write the code to make it singleton across files(without database if it is possible)?