The alternative to using arguments.callee
is to simply name the function, as such:
// Snippet 1, using arguments.callee:
(function(){
document.body.innerHTML += 'qwe';
setTimeout(arguments.callee, 1);
})()
// Snippet 2, using naming:
(function f(){
document.body.innerHTML += 'qwe';
setTimeout(f, 1);
})()
What is stopping the JavaScript engine/compiler from automatically optimizing Snippet 1 into Snippet 2 above? Is there some inherent limitation existing?
MDN's argument basically boils down to:
..
arguments.callee
substantially hinders optimizations like inlining functions, because it must be made possible to provide a reference to the un-inlined function ifarguments.callee
is accessed.However, if we manually name the function and call it via it's name, we are already providing a reference to the function, and thus "hindering optimizations like inlining functions".
Olliej's argument is basically "inlining and tail recursion [becomes] impossible in the general case [whereas it is possible if naming is used]". However no evidence is provided and it seems like a handwave (Also see the comments below his post).
Why is function-naming more performant than using arguments.callee
?