Javascript tail recursion
<p>Why the following code runs so.... slow....... ?</p>

<pre><code>&lt;html&gt;&lt;body&gt;&lt;script type="text/javascript"&gt;
    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);
    };

&lt;/script&gt;&lt;/body&gt;&lt;/html&gt;
</code></pre>
