Early versions of javascript did not allow named function expressions, and because of that we could not make a recursive function expression:
// This snippet will work:function factorial(n) { return (!(n > 1)) ? 1 : factorial(n - 1) * n;}[1, 2, 3, 4, 5].map(factorial);// But this snippet will not:[1, 2, 3, 4, 5].map(function(n) { return (!(n > 1)) ? 1 : /* what goes here? */ (n - 1) * n;}); |
To get around this, arguments.callee was added so we could do :
[1, 2, 3, 4, 5].map(function(n) { return (!(n > 1)) ? 1 : arguments.callee(n - 1) * n;}); |
Warning: The 5th edition of ECMAScript (ES5) forbids use of arguments.callee() in strict mode. Avoid using arguments.callee() by either giving function expressions a name or use a function declaration where a function must call itself. |