Please consider the following:
$(document).ready(function () {
var promise;
(function refresh(){
promise = loadInfo();
promise.done( function() {
$.each(loadedData, function(key, value){
$('#' + key + ' div.info').html(value.label);
})
// Call itself for next iteration
window.setTimeout(refresh, 5 *1000);
})
})()
})
- Do you think each iteration create a new var
promise
or they all reuse the same one? - In case a new var is created for each iteration, can I have an overload overtime (stack overflow!!!) ;) ? The application is displaying data and is supposed to run for long times
- I also have another version with
setInterval((function refresh(){...}), 5 *1000)
without the setTimeout, which one is better? Thoughts?
Thank you