javascript - Asynchronous (setTimeout) lambda doesn't use correct inputs -
this question has answer here:
i got below code within callback of xmlhttprequest
callback function:
// more code before ... // schedule ui update var totsteps = 6; for(var = 0; < 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 above settimeout( function() { (curpulse)(listchangeel[i], 0); }, 125);
executed , listchangeel[i]
does contain right id of cell want update, then, upon first execution of function cell_pulse
parameter elname undefined.
what doing wrong? javascript manage lambda (of lamdba) properly?
thanks,
ema
Comments
Post a Comment