The following snipped of code:
var theAdNets = new Array();
function populateAdNetList() {
}
//update the list every 5 minutes.
setInterval("populateAdNetList()",300000);
//fetch it in 5 seconds.
setTimeout("populateAdNetList();",5000);
Produces the following error:
TypeError: Property '_onTimeout' of object #<Object> is not a function
at Timer.callback (timers.js:83:39)
The populateAdNetList() is a function and not an object. There is no reference to ‘this’ in the body of the function() { }. Why could this be happening?
That is most likely a scope issue. If the function is defined locally in a function or object, then it’s not available in the global scope where the string will be evaluated.
Move the function to the global scope, or use the function reference in the calls instead to avoid the scope problem: