I have a problem with understanding, why my code works correctly :)
Here is the part of my code:
function updateForNextLecturer(current_id, all_lecturers, progressbar)
{
$.getJSON(
'/' + root + 'custom/ajax/update_timetable_lecturer.php?id=' + all_lecturers[current_id],
function(data)
{
if (data.successfull == 0) {
$.stickr({note: "Error occurred.", className: "classic error"});
throw new Error("error");
}
else {
percent = Math.round((current_id + 1) * 100.0 / all_lecturers.length);
progressbar.progressbar({value: percent});
if (current_id + 1 < all_lecturers.length)
updateForNextLecturer(current_id + 1, all_lecturers, progressbar);
else
$.stickr({note: "Success", className: "classic"});
}
}
);
}
This code is required to update timetables for all lecturers. Requests are asynchronous and go one after another, thus webserver is not heavily loaded.
To make request going one after another I need to use recursive callbacks (I suppose this is the only solution). And the question is - why this works correctly, isn't there the maximum nesting level like in PHP? In PHP you can get the following error
Fatal error: Maximum function nesting level of '100' reached, aborting!
I tested this function with thousands of requests, so the nesting level is about several thousands, but no error occurred. Is that because there is no nesting limit in JavaScript at all, or because I don't understand something?
Thanks in advance.