我在xmlHTTPRequest
回调函数的回调中得到了以下代码:
// 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);
}
显然,当执行上述操作时setTimeout( function() { (curPulse)(listChangeEl[i], 0); }, 125);
,listChangeEl[i]
确实包含我要更新的单元格的正确 ID,但是在第一次执行function cell_pulse
参数elName时未定义。
我究竟做错了什么?Javascript 是否正确管理lambda(的lamdba)?
谢谢,
艾玛