This article says the following code will blow up the stack:
function fetchLatest() {
$.getJSON('/wait?id=' + last_seen, function(d) {
$.each(d, function() {
last_seen = parseInt(this.id, 10) + 1;
ul.prepend($('<li></li>').text(this.text));
});
fetchLatest();
});
}
the client-side JavaScript simply uses jQuery’s getJSON method to
perform long-polling against a simple URL endpoint
Doing this recursively is probably a bad idea since it will eventually
blow the browser’s JavaScript stack, but it works OK for the demo.
Is this even true? If so how can we prevent this?
That is not true.
Because
getJSONis asynchronous, the nextfetchLatest()call will start some time after the previous one finishes.If you write synchronous code like that, it will freeze, then throw a stack overflow.