Execution context-javascript Object-oriented advanced

Source: Internet
Author: User

# Execution Context #

* * Definition: When executing a function, it produces a context object that holds variables, function declarations, and this.

* * * function: Used to save the data required for this run time

When an execution context (execution context) is generated, the browser does the following three preparations:

1. Extract the var declared variable and assign the value to undefined
2. Extract the declarative function.
3. Assign this value to the window or to the current object.

Each time a function executes, it produces an execution context,
Because the function parameters are different, there are different calculation results.

# # Global Context Environment # #

Global-level code, such as multiple script tags, that go into the global execution context once executed

1. Extract common variables, such as Var A, and assign a = undefined
2. Extract the declarative function, function fn () {}
3. Assign this value, this point to the window

# # Local Context Environment # #

Generated at the time of the function call, each invocation is generated, and the call is completed and destroyed (except for the closure).

1. Extract common variables, such as Var A, and assign a = undefined
2. Extract the declarative function, function fn () {}
3. Assign this value, this point to the current object
4. Assigning values to parameters
5. Assigning Values to arguments
6. Value scope of free variables, find and assign values

Free variables: Variables that are not declared in the current scope will be searched up to the previous level until the window
Arguments: is a copy of the argument, consistent with the argument.


# # execution Context Stack # #

* * Press stack and out stack * *

Stack: The function is not called when only the global context is executing, each call to the function will produce a local context, which is the stack, that is, into the stack.

Stack: After the function call is completed, it will be out of the stack, destroying the local context of the call

Note: If a function is nested inside a multi-layered function, there will also be nesting of multiple execution contexts
Stacking and stacking are also generated by nesting


Execution context-javascript Object-oriented advanced

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.