The understanding of callee,caller,argument in JavaScript

Source: Internet
Author: User

Argument represents an array of arguments for the current function;

1, the use of callee:

Argument.callee indicates who referred to this function

Other explanations: ( Arguments.callee represents a reference to a function that is currently executing, or a function object that invokes Arguments.callee, which provides an anonymous function with a way of self-referencing. The concept can be better understood through the following examples. )

For example: Var fun=function () {

Console.log (Fun===argument.callee)

}

Fun (); True

Executing the above code, you can see that the result of the alter is true, note that "= = =" is used here, that is, Func is equal to the Arguments.callee object type and value.

Used on recursion, for example:

var r2= (function (n) {

if (n>1) {

Return N*argument.callee (n-1);

}else{

return 1;

}

}) (n)

2, the use of caller:

Returns a reference to the function that called the current function

Functionname.claaer

The FunctionName object is the name of the function being executed

For a function, Claller is defined only when the function is called, and if the function has a top-level invocation, then caller contains null, and if called in the context of the string, the caller property, then the result is the same as functionname.tostring , that is, the anti-compilation text of the function is displayed.

Code

Code highlighting produced by Actipro Codehighlighter (freeware) http://www.CodeHighlighter.com/-->//caller Demo {
function Callerdemo () {
if (Callerdemo.caller) {
var a= callerDemo.caller.toString ();
alert (a);
} else {
Alert ("This is a top function");
}
}
function Handlecaller () {
Callerdemo ();
}

Handlecaller ();//Popup Handlecaller definition

The understanding of callee,caller,argument in JavaScript

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.