Caller returns a reference to a function, which calls the current function; callee puts back the reference of the function itself being executed, which is an attribute of arguments, if you are interested, you can refer to it and may be able to help you
Caller
Caller returns a reference to a function that calls the current function.
Note that:
1. This attribute is only useful when a function is executed.
2. If a function is called by the top layer in a javascript program, null is returned.
FunctionName. caller: functionName is the currently executed function.
The Code is as follows:
Var a = function (){
Alert (a. caller );
}
Var B = function (){
A ();
}
B ();
In the above Code, B calls a, and a. caller returns a reference of B. The result is as follows:
If you call a directly (that is, a is called in any function, that is, the top-level call), return null:
The Code is as follows:
Var a = function (){
Alert (a. caller );
}
Var B = function (){
A ();
}
// B ();
A ();
Output result:
Callee
Callee puts back the reference of the function itself being executed. It is an attribute of arguments.
Pay attention when using callee:
1. This attribute is valid only when the function is executed.
2. It has a length attribute that can be used to obtain the number of parameters. Therefore, it can be used to compare whether the number of parameters and real parameters are consistent, that is, to compare whether arguments. length is equal to arguments. callee. length
3. It can be used to recursive anonymous functions.
The Code is as follows:
Var a = function (){
Alert (arguments. callee );
}
Var B = function (){
A ();
}
B ();
A is called in B, but it returns a reference. The result is as follows: