function runProcess(){
var todo = items.concat();
setTimeout(function(){
process(todo.shift());
if(todo.length > 0){
setTimeout(arguments.callee, 25);
} else {
callback(items);
}
}, 25);
}
我试图将这个 block 重构为一个函数
function doWork(todo){
process(todo.shift());
if(todo.length > 0){
setTimeout(arguments.callee, 25);
} else {
callback(items);
}
}
但是这次给定的数组从头开始重复自身
我认为问题出现在 arguments.callee 中,那么我可以使用什么来代替它呢?
最好的问候
最佳答案
只需为您的匿名函数命名,这样您就可以通过它的名字来调用它。
function runProcess(){
var todo = items.concat();
setTimeout(function step() { // give it a name
process(todo.shift());
if(todo.length > 0){
setTimeout(step, 25); // call it by its name
} else {
callback(items);
}
}, 25);
}
关于javascript - 我还能用什么来代替 arguments.callee?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3874922/