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