Introduction to arguments, caller and callee in JavaScript

Source: Internet
Author: User
1. preface what is arguments, caller, callee? What is the role of javascript? This article will give a basic introduction to this. 2. argumentsarguments: During function calling, a hidden pair named arguments is automatically generated inside the function... SyntaxHighlighte 1. preface what are arguments, caller and callee? What is the role of javascript? This article will give a basic introduction to this. 2. argumentsarguments: When a function is called, a hidden object named arguments is automatically generated within the function. This object is similar to an array, but not an array. You can use the [] operator to obtain the real parameters passed during function calls. [Html] Arguments TestScript function testArg () {alert ("real parameter count:" + arguments. length); for (var I = 0; I <arguments. length; I ++) {alert (arguments [I]) ;}} testArg (11); // count: 1 testArg ('hello', 'World '); // count: 2 scriptIt looks simple. Note the information of the real parameters saved by argument. It says that arguments is not an array. Why? Run the following sections to know [javascript] (function () {alert (arguments instanceof Array); // false alert (typeof (arguments); // object }) (). If you are not clear about how to write the function immediately, refer http://blog.csdn.net/oscar999/article/details/8507919 The arguments object is created only when the Function is called. When not called, its value is null: [javascript] alert (new Function (). arguments); // return null the complete Syntax of arguments is as follows: [function.] arguments [n] Parameter function: option. Name of the Function object currently being executed. N: option. The index of the parameter value starting from 0 to be passed to the Function object. 3. When a caller function calls another function, the called function automatically generates a caller attribute pointing to the function object that calls it. If the function is not currently called, or is not called by other functions, caller is null. [Javascript] script function testCaller () {var caller = testCaller. caller; alert (caller);} function aCaller () {testCaller ();} aCaller (); 4. callee when the function is called, its arguments. the callee object points to itself, that is, a reference to itself. Because arguments is valid only when the function is called, arguments. callee does not exist (that is, null. callee) when the function is not called, and an exception occurs when it is called. [Javascript] script function aCallee (arg) {alert (arguments. callee);} function aCaller (arg1, arg2) {aCallee ();} aCaller (); script

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.