js named function in parameter, can not access out of function
Because the 5th edition of ECMAScript forbids use of arguments.callee() in strict mode.
So I decided do not use the callee, instead , I use a named function
The example in mdn
function factorial (n) {
return !(n > 1) ? 1 : factorial(n - 1) * n;
}
[1,2,3,4,5].map(factorial);
become:
[1,2,3,4,5].map(function factorial(n) {
return !(n > 1) ? 1 : /* what goes here? */ factorial(n - 1) * n;
});
This is a good idea, but I want to reuse the function factorial
DEMO
function d(x){return x;}
d(function a(){});
d(a);// this is not work, a is undefined(works in ie, failed in ff and chrome)
This is bother me, as I know, the scope in js is function-level, why the second a is undefined ?
calleeby use the named function.