Stop Using arguments.callee
Please, it’s no longer needed. It’s also deprecated and uncool. I still see authors use it to recursively call an anonymous function when really, they should be using a named function.
E.g. instead of this (from MDC):
function makeFactorialFunc() {
alert('making a factorial function!');
return function(x) {
if (x <= 1)
return 1;
return x * arguments.callee(x - 1);
};
}
var result = makeFactorialFunc()(5); // returns 120 (5 * 4 * 3 * 2 * 1)
do this:
function makeFactorialFunc() {
alert('making a factorial function!');
return function innerFactorialFunc(x) {
if (x <= 1)
return 1;
return x * innerFactorialFunc(x - 1);
};
}
var result = makeFactorialFunc()(5); // returns 120 (5 * 4 * 3 * 2 * 1)
We give the anonymous function a name (innerFactorialFunc in this case) so it can be referenced in its function body. Makes sense.
arguments.callee is a remnant of a time when named functions couldn’t be used this way. Please, let it die.
Edit: take heed, however, JScript has a number of bugs with named functions