I do not know much about the specifics of each javascript implementation in each browser. However, I know that when using setTimeout, the method passed in the call is called in a separate thread. So using the resulting setTimeout method inside the method will cause its stack to grow indefinitely until it causes a stack overflow? Or will he create a separate column and destroy the current frame when it goes out of focus? Here is the code I'm curious about.
function pollServer()
{
$.getJSON("poll.php", {}, function(data){
window.setTimeout(pollServer, 1000);
});
}
window.setTimeout(pollServer, 0);
I want to poll the server every second or so, but I don’t want to spend CPU cycles on the “lock cycle” - I also don’t want to set timelimit on how long the user can access the page or before their browser dies.
EDIT
Using firebug, I set some breakpoints and looked at the "Script → Stack" panel, that the call stack is literally just "pollServer" and it does not grow per call. This is good - however, do other JS implementations do differently?
source
share