爲什麼下面的代碼運行得如此......慢.......?Javascript尾遞歸
<html><body><script type="text/javascript">
var i = 0;
f();
function f() {
if (i == 5000) {
document.write("Done");
} else {
i++;
tail();
}
}
function tail() {
var fn = tail.caller;
var args = arguments;
setTimeout(function() {fn.apply(this, args)}, 0);
};
</script></body></html>
非常感謝您的解釋! – 2010-05-23 14:51:48
我一定會考慮Web Workers! – 2010-05-23 15:04:55