Differences between caller and callee
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
Caller
Caller returns a reference to a function that calls the current function.
Note the following before using this attribute:
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.
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:
var b = function() { a(); }
If you call a directly (that is, a is called in any function, that is, the top-level call), return null:
var a = function() { alert(a.caller); } var b = function() { a(); } //b(); a();
Output result:
Null
Callee
Callee puts back the reference of the function itself being executed. It is an attribute of arguments.
Note the following 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.
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:
var a = function() { alert(arguments.callee); }