Page 1 of 1
Using local objects inside setTimeout
Posted: Mon Feb 12, 2007 5:26 pm
by alex.barylski
I'm sure I've done this before, but I can't seem to repeat my previous solutions...
I have an object created inside a function scope and inside that function I call setTimeout()
I need to access that object inside setTimeout()
Any ideas???
Posted: Mon Feb 12, 2007 9:21 pm
by Kieran Huggins
Any variables used in a function which are not explicitly defined as var are assumed to belong to an outer scope, possibly to the Global (window) Object. Are you using "var object = new Object()" or similar?
If all else fails, attach it to window directly: "window.myObject = new Object()"
Posted: Tue Feb 13, 2007 2:25 am
by alex.barylski
Kieran Huggins wrote:Any variables used in a function which are not explicitly defined as var are assumed to belong to an outer scope, possibly to the Global (window) Object. Are you using "var object = new Object()" or similar?
If all else fails, attach it to window directly: "window.myObject = new Object()"
Oh really? Cool...so if I don't use
var it's assumed global or at least outside the scope of the function which invokes setTimeout...cool I did not know that...
Posted: Tue Feb 13, 2007 10:09 am
by Kieran Huggins
one of the (potentially aggravating) subtleties of javascript
Working now?