0

I want to create a function that gets a global variable as a parameter and changes it after a timeout.

function change(variable, value, time)
{
    setTimeout(function() { variable= value; }, time);

}

I do not know what variable is in advance.

problem is when I do this the assignment doesn't hold for outside the function.

How can I tell the function that var is global?

Dotan
  • 6,602
  • 10
  • 34
  • 47
  • 5
    To make it work, you would use `window[varName] = value`, but don't do that. You shouldn't be abusing global variables like this. – Alnitak Jan 26 '15 at 12:01
  • `variable` really isn't that much better, except for not being a reserved word. – Alnitak Jan 26 '15 at 12:03
  • An interesting answer here => http://stackoverflow.com/questions/18178728/passing-a-global-variable-to-a-function – kkaosninja Jan 26 '15 at 12:04

0 Answers0