Ok, I don’t know if I am going to be able to fully describe the scope of what I am doing, but hopefully I can convey some level of it here and hopefully someone will understand. So..
I have these global variables I am defining in my javascript ie:
var abc = '';
var def = '';
var ghi = '';
With these variables I am able to define them later in my script through functions. So they are then reusable by other functions later. That part I have down fine. Now I have an interesting notion that has me stumped where the. The variable is this case is ultimately an object I pass around from function to function, that I can use for various comparisons, and update it as needed. Now Ive reached a point where I need to redefine the whole object at the end of a particular function. But I am merely passing around the object itself so the reference is lost as to which object was the starting point.
So now I am trying to figure out is there a way I can redefine it, say my function is
function monkey(var)
{
//code to do stuff
//something here after stuff to redefine var as the object it once was referenced
//example ghi = something_from_code_generation_above
}
monkey(abc);
monkey(def);
monkey(ghi);
where after making calls like that the abc object update, or the def object updates, or the ghi object updates. But keeping it confined within the function and not through a closure like
ghi = monkey(ghi);
The only way I know how to do this is by passing the enclosing scope as an extra parameter, and passing the name, rather than the value of the variable.
If you already know that all variables passed will be in a particular scope (e.g. they are all part of some known named object) You can just pass the variable name by string.
If they are all global variables, as you indicate in your question, do: