2015.09.22

Source: Internet
Author: User

During the pre-parsing process:
1, variable, variable declaration: The default assignment is undefined
2. This: Assign value
3. Function declaration: Assign Value
The readiness of these three kinds of data we call "execution context" or "execution context";


Variables in the function:
If in the function, in addition to the above data, there will be other data, such as
function fn (x) {
Console.log (arguements);
Console.log (x);
}
FN (10);
Description: Each time a function is called, a new execution context is generated because different invocations can produce different execution environments.
var a = 10;
function fn () {
Console.log (a); A is a free variable
}//When the function is created, it determines the scope for which a is to be evaluated
Function Bar (FN) {
var a = 20;
FN (); Print "10" instead of "20"

}
Bar (FN);
Description: When defining a function, the scope of the internal variables of the function body has been determined.


Execution Context Stack:
When you execute global code, a global context is generated, and a function context is generated each time the function is called. When the function call is complete, the function context and the data in it will
Is destroyed and is re-returned to the global context environment. The active execution context is only one, in effect, a stack and stack-out process.

var a = 10;
c = 20;
function fn (x) {
var a = 100;
c = 200;
function bar (x) {
var a = 1000;
d = 4000;
}
}
Bar (100);
Bar (200);
}
FN (10);

Scope and Context relationships:
var a = 10;
c = 20;
Create a global context environment
Global scope
function fn (x) {
var a = 100;
c = 200;
Generates the FN (10) Contextual environment
fn Scope
function bar (x) {
var a = 1000;
d = 4000;
producing a bar (100) Contextual environment
producing a bar (100) Contextual environment
Bar scope
}

Bar (100);
Bar (200);
}
FN (10);

Scope: Scope is just a "site", an abstract concept, where there is no variable, to get the value of a variable through the execution context of the scope, under the same scope, different calls produce
Different execution contexts, which in turn produce values for different variables.

2015.09.22

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.