Read ecmascript again

Source: Internet
Author: User

In the past few days, I spent some time reading ecmascript. The following are some of my summary. Under this record.

Part 1: understanding of variable objects

1) What is a variable object? Data access and reading mechanisms are variable objects. Variable objects are execution context-related objects, including:
    • Variable (VAR)
    • Function Definition (FD)
    • Function Parameters
2) about function arguments   Function Foo (x, y, z ){
Z = 40;
Y = 50;
Alert (arguments. callee = Foo );
Alert (arguments. Length); // 1
Alert (arguments [1]); // undefine
Alert (arguments [2]); // undefine
}

Foo (10) The arguments object is one of the activation objects in the context of function execution. It has three attributes: 

    1. Callee references the current function
    2. Actual length parameter count
    3. Properties-index function parameter value
Note: If the actual number of parameters is smaller than the number of defined parameters, it cannot be obtained through arguments.     3. Differences between var A = 1 and a = 1  
    • VaR A is a variable object that cannot be deleted through Delete.
    • A indicates that the attribute can be deleted through Delete.
The biggest difference between a variable and an attribute is that a variable has an attribute [dontdelete], which indicates that it cannot be deleted. Note: An execution context is invalid for this rule, that is, Eval ('var A = 1 ')   4. Let's look at the example.  
Alert ();   Alert (B );   Window. A = 1;   A = 1;   This. A = 1;   VaR B = 2;
========================================================== ====== Part 2: understanding about this   1) This is determined when the context is enteredCodeThe execution period remains unchanged

2) What changes affect the value of this:
This is provided by the activation context code and the caller, that is, the parent context of the called function.
The method for calling a function determines the value of this. 3) What is the reference type?
Includes two attributes:
1. Objects with attributes of the base
2. attribute name of the property name object in base
The value of the reference type is from 2:
1. when processing a token
2.Attribute accessors 4) this as the constructor's Function
This is set as the newly created object. 5) a general rule
This is provided by the caller and determined by the method of calling the function.
In 2 cases:
1. If the value of the reference type is on the left of (), this will be set as a base object of the reference type.
2. In other cases, all values are null, but this null value is automatically converted to a window object. 6) This is a dynamic feature that is determined during function execution. ========================================================== ==========

Part 3: understanding of the scope chain

1. For a function, the variable object is the activation object. For a global context, the variable object is the global variable itself.


2. the scope chain is actually a list of all internal context variable objects.   3. The function scope chain is created when the function is called, including the active objects and the internal scope attributes of the function.   4. Internal functions[[Scope]Mechanism: Scope is a layered chain that contains all upper-layer objects. It belongs to the context of the current function and is saved in the function when the function is created. Scope is saved during function creation and is a static feature. 5. the lifecycle of a function can be divided into two phases: the creation phase and the activation (CALL) phase. 6. The function context is Scope = AO + [[Scope ] AO is the active object   7. What is a closure? A closure is a combination of function code and [[Scope] attributes. [[Scope] includes the creation of functions. All variables in the context and upper context can use the lexical scope chain of variables when the function is activated. Found.   8. Pass Function The [Scope] attribute of the created function always contains only global objects.   9. If it is not found in the scope chain, the prototype chain will be queried.   ========================================================== ============================ Part 4: Closure Comprehension   1. ecmascript is a language with static (lexical) scopes.

  2. Closure is a combination of Context Data of the function code block and the code block.   3. In ecmascript, the closures created in the same context use the same [Scope] attribute   4. Theoretically, all functions are closures.   You are welcome to make a brick !!  

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.