Arguments, callee, and caller in javascript _ basic knowledge

Source: Internet
Author: User
What are arguments, caller, and callee in javascript? What is the role of javascript? This article will give a basic introduction to this. I hope you will like it. What is arguments?

When calling a function, arguments creates a similar array but not an array object, and stores the parameters actually passed to the function, it is not limited to the parameter list of function declaration.

What does Nima mean?

Write a demo. See the code below.

      Arguments    
     Script function obj () {// use instanceof to determine arguments console. log ('arguments instanceof Array? '+ (Arguments instanceof Array); console. log ('arguments instanceof Object? '+ (Arguments instanceof Object); console. log (arguments);} obj (); script

Run the code and use the chrome debugger to obtain

I use instanceof to judge arguments. According to the print result, arguments is an object.

Then expand the output arguments. We can see that it contains many attributes, as well as callee.

Next, we modify the above Code and pass parameters to the obj function when calling the obj function, but the obj function does not have parameters.

For specific code, see

      Arguments    
     Script function obj () {console. log ('arguments instanceof Array? '+ (Arguments instanceof Array); console. log ('arguments instanceof Object? '+ (Arguments instanceof Object); console. log (arguments);} // pass the parameter obj ('monkey', 'love', 24) to obj; script

Use the chrome debugger to obtain

As you can see, arguments contains three parameters we pass to it: "monkey", "love", and 24.

So why does arguments actually store the parameters passed to the function, rather than the declared parameters.

What is callee?

Callee is a member of the arguments object. Its value is "Function object being executed ".

What does it mean?

Let's write a demo and check the output.

The code and result are shown in the following figure.

      Callee    
     Script function obj () {// use callee console. log (arguments. callee);} obj (); script

As shown in the preceding figure, arguments. callee is a function pointing to the arguments object. Here it is obj.

What is caller?

Caller is an attribute of a function object that stores the function that calls the current function.

Note: It is called. It not only contains closures. If there is no parent function, it is null.

It's still the same. Let's keep writing a demo.

The Code is as follows:

      Caller    
     Script // child is a function in parent and executes the child function parent () {function child () {// in parent. The parent function of child is the parent console. log (child. caller) ;}child () ;}// parent1 is not called by someone else. function parent1 () {// parent1 has no parent function console. log (parent1.caller);} // parent2 calls child2 function parent2 () {child2 ();} function child2 () {console. log (child2.caller);}/* execute the parent nested child function parent1. No nested function parent2 calls child2. child2 is not a function nested in parent2 */parent (); parent1 (); parent2 (); script

Open the chrome debugger.

Can I understand caller in combination with code and understanding?

Related Article

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.