Caller
Caller returns a reference to a function that calls the current function.
Use this property to note that:
1 This property is useful only if the function is executed
2 returns NULL if the function is called from the top level in a JavaScript program
FunctionName.caller:functionName is the currently executing function.
Copy Code code as follows:
var a = function () {
alert (A.caller);
}
var B = function () {
A ();
}
b ();
In the code above, B calls a, then A.caller returns a reference to B, and the result is as follows:
Returns null if a direct call to a (that is, a call in any function, that is, the top-level call) is returned:
Copy Code code as follows:
var a = function () {
alert (A.caller);
}
var B = function () {
A ();
}
b ();
A ();
Output results:
Callee
Callee the reference to the function itself being executed, which is a property of the arguments
when using callee, be aware that:
1 This property is valid only if the function is executed
2 It has a length property that can be used to obtain the number of formal parameters, so it can be used to compare the number of parameters and arguments to be consistent, that is, whether the comparison arguments.length equals arguments.callee.length
3 It can be used to recursively anonymous functions.
Copy Code code as follows:
var a = function () {
alert (Arguments.callee);
}
var B = function () {
A ();
}
b ();
A is called in B, but it returns a reference to the a itself, with the following result: