0

I would like to have on a separate script some logic and I need to let it know on which global variable all of my operations must be done: how can I pass to a function a reference to the variable?

function setVariable(variable){
   //Here I let the script know on which variable it should work
   //Example var x = reference to 'variable'
}

function run(){
   if(x === 0){ ...
   ... }
}

I cannot "copy" the variable value because it's global and it can change anytime and this script has to read the updated value.

Brbcod1
  • 161
  • 1
  • 11
  • 2
    If you declared the variable (`x`) inside `setvariable` it'll not be global, you can't refer it in `run` function. – Teemu Feb 18 '20 at 17:43
  • 1
    Change your global variable to be an object with property values. – trincot Feb 18 '20 at 17:43

0 Answers0