hel*_*ker 0 javascript recursion settimeout
此代码不起作用:
var counter = 0;
kick(print);
function kick(f) {
setTimeout(function(){
f(); // problem here;
kick();
}, 500);
}
function print(){
console.log(counter++);
}
Run Code Online (Sandbox Code Playgroud)
浏览器控制台给出以下错误:
Uncaught TypeError: f is not a function
如何f()在所需的点正确调用?
再过f一遍:
function kick(f) {
setTimeout(function(){
f(); // problem here;
kick(f);
}, 500);
}
Run Code Online (Sandbox Code Playgroud)