开发者

How to resolve 'TypeError: Property '_onTimeout' of object #<Object> is not a function' in node?

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 fu开发者_如何学Cnction 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:

//update the list every 5 minutes.
setInterval(populateAdNetList,300000);
//fetch it in 5 seconds.
setTimeout(populateAdNetList,5000);


You have to pass function to setInterval. Not string and not the result of the function (until it is also a function). The proper syntax:

setInterval(populateAdNetList, 300000);
setTimeout(populateAdNetList, 5000);


try simply

setInterval(populateAdNetList,300000);
//fetch it in 5 seconds.
setTimeout(populateAdNetList,5000);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜