Caller
function Fun Caller returns the function object that calls fun, which is the execution environment for fun, and returns null if the execution environment for fun is window
function Fun () {
console.log (Fun.caller)//must be written in fun, because caller is only valid during function execution
}
fun ();
The result is: null
One layer below.
function A () {
fun ();
function Fun () {
console.log (Fun.caller)//must be written here in fun, because caller is only valid during function execution
}
}
a ();
The result is: a function
In a layer of wrapping
function A () {
B ();
Function B () {
fun ();
function Fun () {
console.log (Fun.caller)//must be written here in fun because caller is only valid during function execution
}}
a ();
The result is: b function
callee This property is above the arguments of the function
function A () {
console.log (Arguments.callee)
}
A ();
The result is the A function itself
The following is a classic factorial function
function sum (num) {
if (num <= 1) {return
1;
} else{return
num * (SUM (num-1)
}}
Console.log (SUM (5))
/Result: 5*4*3*2*1=120
In order to avoid the function name modification causes the function internal error, changes writes below
function sum (num) {
if (num <= 1) {return
1;
} else{return
num * (Arguments.callee (num-1))
}
console.log (SUM (5))
//Result: 5*4*3*2*1=120
Another use of callee
function A (num1,num2,num3) {
console.log (arguments.length);//The argument length is 1
console.log ( arguments.callee.length)//Line parameter length is 3
}