Caller and Callee's difference introduction and presentation results _ basic knowledge

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.