I have a variable declared at the top of my function as this.current_test = null; and then down the line I have a setInterval function and I need to set the variable to a new parameter…
this.current_test.failed = true;
Code:
timer = this.window.setInterval(function()
{
this.window.clearInterval(timer);
this.current_test.failed = true;
},1000);
}
However I am getting a TypeError: 'undefined' is not an object (evaluating 'this.current_test.failed = true' error
And I assume this is because this.current_test is not defined inside the setInterval function, so how can I edit that variable?
The scope of your ‘this’ in the timer function will not refer to this.window. this scope is that for function only what you can do
By the way for reffering to window why do you need ‘this’ and also the if cuurent_test is a global variable then you can declare like
and you can use the global variable inside the timer function