I'm having some interesting issues with passing in variables from within an object into setTimeout. At first, I tried putting the function I was calling from setTimeout on my object so that I wouldn't have to pass any variables into it (I was hoping it could access my object by itself). That didn't work, apparently because the function somehow became global when I called it from setTimeout, and no longer had access to my object's variables.
This was my next attempt, but it doesn't work either:
function MyObj() {
this.foo = 10;
this.bar = 20;
this.duration = 1000;
setTimeout(function(){
AnotherFunction(this.foo, this.bar)
}, this.duration);
}
So, how exactly can I pass in a variable into setTimeout from within an object? No, AnotherFunction won't be able to directly access MyObj for various unrelated reasons, so that's out of the question too.
AnotherFunctioncalled for? by convention, constructors start with Capitalized letters. isAnotherFunctionanother constructor? or just a function to be called?AnotherFunctionis just a function to be called. =)