Javascript tail recursion
Posted
by Misha Moroshko
on Stack Overflow
See other posts from Stack Overflow
or by Misha Moroshko
Published on 2010-05-22T16:00:36Z
Indexed on
2010/05/22
16:10 UTC
Read the original article
Hit count: 314
JavaScript
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>
© Stack Overflow or respective owner