*JS: Execution Environment, variable object, active object, and scope chain

Source: Internet
Author: User

var a=1; function B (x) {    var c=2;    Console.log (x);} B (3);

• Execution Environment (execution context), also known as environment, execution context, context environment, execution context:
Each time the controller goes to the ECMAScript executable code, it goes into an execution context. The execution context (referred to as-EC) is
An abstract concept in the ECMA-262 standard used to differentiate between the concept of executable code (executable codes).
In layman's terms, the function of JS can not only see what variables are inside the function, but simply do the arithmetic
You need to take a value based on the environment in which the function is located, such as: variables, function declarations, and arguments, before executing the code,
All the variables are taken out beforehand, some directly assigned, some first with undefined to occupy a pit) operation.
The execution environment mainly contains the variable object and the scope chain two parts content.

• Variable objects (variable object):
Variable objects are part of the execution environment, and each execution environment has an object that is used to store variables, function declarations in the execution environment, and
Arguments, this object is the variable object that executes the environment.
The variable object of the global environment always exists, and the local environment variable object exists only in the process of function execution, and each function has its own
Execution environment.
The contents of the Global Environment object include: Var a=undefined, function B () {...}, this=windows. and a Bureau like B ()
Part Variable object content includes: Var c=undefined, arguments=[3], x=3, this=windows.

• Active objects (Activation object):
In the context of function execution, VO is not directly accessible at this time by the active object (Activation object, abbreviated as AO) to play Vo's
Role.

• Scope Chain:
When function B () {} is created, a scope chain that contains a global variable is created, and the scope chain is stored in the [[Scope]] Genus
In the sex. When B () is called, an execution environment is created and then the execution environment is built from the object in the [Scope] property of the copy function
Domain chain. Another active object (used here as a variable object) is then created and pushed into the execution environment scope front end. For this example
In allele's execution environment, its scope chain includes 2 variable objects: A global variable object and its internal active object.
Obviously, a scope chain is essentially a pointer to a variable object list, which simply references but does not actually contain variable objects.

• The search mechanism for variables:
First search the local variables, if not found, go to the previous layer to find, until the search all variables, if not found, return undefined.

*JS: Execution Environment, variable object, active object, and scope chain

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.