I got the below code within a callback of xmlHTTPRequest
callback function:
// some more code before
...
// schedule the UI update
var totSteps = 6;
for(var i = 0; i < listChangeEl.length; ++i) {
// callback pulse function
var curPulse = function cell_pulse(elName, curCnt) {
console.log("Accessing element: " + elName);
var curEl = document.getElementById(elName);
console.log("Element: " + elName + " = " + curEl);
var curColor = RGB2HTML(255, 255*(curCnt/totSteps), 255*(curCnt/totSteps));
if(curCnt < totSteps) {
// recursion here!
setTimeout( function(){ cell_pulse(elName, curCnt+1); }, 125);
}
};
// start it!
setTimeout( function() { (curPulse)(listChangeEl[i], 0); }, 125);
}
Apparently when the above is setTimeout( function() { (curPulse)(listChangeEl[i], 0); }, 125);
is executed , listChangeEl[i]
does contain the right id of a cell I want to update, but then, upon first execution of function cell_pulse
the parameter elName is undefined.
What am I doing wrong? Does Javascript manage lambda (of lamdba) properly?
Thanks,
Ema