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.
Copy codeThe 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:
Copy codeThe 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.
Copy codeThe 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: