View Full Version : Problem with 'this'
02-02-2007, 03:01 PM
I think this should keep alerting 'hello' but for some reason it doesn't. Can you help me out with this?
02-02-2007, 03:49 PM
this comes from the object part of object.member(). If you move a function from object to anotherObject, and call anotherObject.member() then the value of this will be anotherObject.
In this case, you're not calling the function yourself, however. setTimeout calls it for you. But you handed setTimeout the function object itself, which has no binding to the this object. So, the this object will be the global object instead, like all normal function calls. Is there a way to solve this? Of course.
02-02-2007, 03:58 PM
I see it now!
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.