The problem is that setTimeout () forces javascript to use the global scope. Essentially, you are calling the method () class, but not from "this". Instead, you simply tell setTimeout to use the "method" function, without any specific scope.
To fix this, you can wrap a function call in another function call that references the correct variables. It will look something like this:
test.protoype.method = function() { var that = this;
"which may be" this "because callMethod () is within scope.
This problem becomes more complicated when you need to pass parameters to the setTimeout method, since IE does not support more than two parameters for setTimeout. In this case, you will need to read closures .
In addition, as a side element, you are setting yourself up for an infinite loop, since the () method always calls the () method.
Daniel Lew Feb 26 '09 at 16:37 2009-02-26 16:37
source share