My webapp is based on a common script, where I define common functions and a global variable and dynamically loaded scripts that process them. So far, the only way to export a global variable is to replace any event with window["myGlobalVar"], but I find it very ugly. Is there a better way to do this?
Here is an illustration
function incrementVariable() {window["myGlobalVar"]++;}
window["incrementVariable"] = incrementVariable;
window["myGlobalVar"] = 0;
and in another script
alert(myGlobalVar);
incrementVariable();
alert(myGlobalVar);
I am looking for a way to use directly myGlobalVarin both files because it would be more elegant. However, I need to set a window["myGlobalVar"]pointer, not a copy of the object, and I'm not sure how to do this on simple types.
Is it possible? Is encapsulation myGlobalVarin the Objectonly other way?
Thanks so much for your lights.