①, caller
Caller returns a reference to the function that called the current function.
Use this attribute to note:
1 This property is used only when the function is executed
2 If the function is called by the top-level in a JavaScript program, it returns null
FunctionName.caller:functionName is a function that is currently executing.
Example 1: Copy the Code code as follows:
varfunction() {alert (A.caller); } varfunction() {a (); } b ();
In the above code, B calls A, then A.caller returns a reference to B, the result is as follows: Example 2: return null
<! DOCTYPE html>var function () { alert (a.caller); } A (); </script> ②, callee
Callee returns a reference to the function itself that is being executed, which is a property of the arguments
Note When using callee:
1 This property is valid only if the function is executed
2 It has a length property, which can be used to get the number of formal parameters, so it can be used to compare the number of parameters and arguments, that is, whether the comparison arguments.length equals arguments.callee.length
3 It can be used to recursively return anonymous functions.
Example 1: Return a reference to the function itself
var a = function () {
alert (Arguments.callee);
}
var B = function () {
A ();
}
b ();
A is called in B, but it returns a reference to a itself, with the following result:
Example 2: Getting the formal parameters of a function
Summary: Caller is a function that returns a reference to the function that is called callee is returned itselfThe difference between caller and callee