The secret between the arguments object and the call Object Function

Source: Internet
Author: User

Call object is a concept in the scope chain. In chapter 8 of the JS authoritative guide. Note: It has nothing to do with function call. This is just a name, but in ecmascript, another name is activation object.

Some people have already copied part of the call object in the JS authoritative guide: see scope chain lexical scope and closure (1) of wheat) and belltoy's JavaScript lexical scopes, call objects, and closures (maybe the Chinese version of the JS authoritative guide translates call objects into: Call objects ).

Rhino booksThere should beA very vivid description of the scope chain

The scope chain lexical scope and closure of wheat (1)

This "should have" shows this articleArticleThe author did not read the JS authoritative guide, or did not look at it carefully.

If you have read the previous two posts and are dizzy, please refer to the original article in the reference rhino book below:

When the javascript interpreter calls a function, the scope chain of the function is effectively formed when the function is defined. Then, the function adds a stuff called call object or activation object to the front of the scope chain. Call object initializes an attribute called arguments that references the function arguments object. Then, call object adds the parameter with the name of the function, and all local variables declared with VAR are added. The call object is at the top of the scope chain. Local variables, function parameters, and arguments objects are all within the function scope. That is to say, when they go deep into the next scope chain, they will certainly mask all attributes with the same name.

In call object, this is a keyword rather than an attribute.

In zakas's answer to baranovskiy's JavaScript quiz (translated in Chinese) 4th, the arguments object contains the activation object in ecmascript, So I remembered it again ..

The following references the contents of the arguments object in section 10.1.8 of ECMA-262 3rd:

For all non-negative integer Arg values smaller than the attribute length, such attributes with tostring (ARG) and its attributes (feature) {dontenum} will be generated. The initial value of this attribute is the real parameter value provided by the caller (caller. The first parameter value corresponds to Arg = 0, and the second parameter is Arg = 1. When Arg is less than the number of all parameters of the function object, this attribute shares its value with the corresponding activation object attribute. That is to say, if this attribute is changed, the value of the activation object attribute will also change, and vice versa.

In section 2.1.2 "proficient in JavaScript", there are not many arguments objects.

Update: Someone in China uses the name "pre-resolution" to link the call object and the variable declaration to the top of its scope, see Miller's JavaScript pre-resolution related article.

(End)

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.