Introduction to arguments, caller, and callee of "turn" JavaScript

Source: Internet
Author: User

1. Preface

Arguments, caller, what is callee?

What is the role in JavaScript? This article will do some basic introduction.

This article was reproduced from: http://blog.csdn.net/oscar999/article/details/8511335

2. Arguments
Arguments: When a function is called, a hidden object named arguments is automatically generated inside the function. The object is similar to an array, but not an array. You can use the [] operator to get the arguments that are passed when the function is called.
<!--by oscar999 2013-1-16--> <!      DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" > functionTestarg () {alert ("Real parameter count:" +arguments.length);  for(vari = 0; i < arguments.length; i++) {alert (arguments[i]); }} testarg (11);//count:1Testarg (' Hello ', ' world ');//Count:2</script> </body> 

It looks simple. It is important to note that the argument holds the information of the arguments.

It says that arguments is not an array. Follow the sections below to find out

    (function  () {          instanceof//  false          alert (typeof  //  object      }) ();  

The arguments object is created only when the function is called, and its value is null when it is not called:

    Alert (new Function (). arguments); // return null  

The complete syntax for arguments is as follows:
3. Caller
When a function calls another function, the called function automatically generates a caller property that points to the function object that called it. If the function is not currently called, or is not called by another function, caller is null.

    <script>      function  testcaller () {          var caller = Testcaller.caller;          alert (caller);      }             function Acaller () {          testcaller ();      }            Acaller ();  

4. callee

When a function is called, its Arguments.callee object points to itself, which is a reference to itself.
Because arguments is valid when a function is called, Arguments.callee does not exist when the function is not called (that is, Null.callee), and the dereference causes an exception

    <script>      function  Acallee (ARG) {        alert (Arguments.callee);      }             function Acaller (arg1, arg2) {Acallee ();}            Acaller ();       </script>  

Introduction to arguments, caller, and callee of "turn" JavaScript

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.