Javascript tail recursion
- by Misha Moroshko
Why the following code runs so.... slow....... ?
<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>