var tempOut = false;
var foo = function () {
this.tempIn = false;
this.counter = function () {
setTimeout(function () {
this.tempIn = true;
tempOut = true;
},5000);
};
};
var myFunction = new foo();
myFunction.counter();
console.log(tempOut+ " " + myFunction.tempIn);
Hey there, I have a simple code that changes variables after 5 seconds. There are 2 variables: one global(tempOut) and one local (tempIn). When I create object from function foo, and start counter function after 5 seconds both variables should be set to true, but only tempOut changes. What I do wrong?