Execution Environment and scope
I. Global variables and local variables
Each execution environment has variable objects associated with it (variables and functions are stored here), and the global execution environment is the outermost execution environment, and the objects representing the execution environment are different depending on the host in which the ECMA implementation resides. In a Web browser, the global execution environment is considered a Window object.
Each function has its own execution environment, has its own corresponding variable object (arguments object), when the execution flow into a function, the function of the environment will be pushed to an environment stack, after the function is executed, the stack will pop up its environment, give control to the previous execution environment.
When the code executes in an environment, the scope chain of the variable object is created.
Two. Extend the scope chain (a bit does not understand the extension?) )
Catch in Try-catch (the Error object caught by IE8 before catch is in a variable object with the execution environment, not in the variable object of the Catch statement, IE9 fixes the problem)
With statement:
(function Addurl () {
var qs= "? a=4";
With (location) {
Console.log ("href:" +href);
The properties of the access location were successful
var Url=href+qs;
}
Console.log ("href:" +href);
Failed to access the properties of location
Console.log ("URL:" +url);
})();
With the variable object contains all the properties and methods of the Location object, the variable object is added to the scope chain front, and the properties and functions of the location can only be accessed within the scope of with, and the Addurl function outside the with cannot be accessed, However, the Addurl function outside with has access to the new variable URL within with.
(This is inconsistent with the "no block scope" knowledge, because the location property of the with inside is not accessible outside of with, so with the inside itself there is a variable object, but the following knowledge point mentions that the statement has no block scope)
(with is not allowed in strict mode, with heavy usage can affect performance)
Three. No block scope
If else, the variables defined by the For statement are stored in the most recent execution environment and do not have an execution environment on their own.
Variables declared with Var are automatically added to the most recent execution environment.
The identifier of the query is from near to far.
Memory
I. automatic garbage collection mechanism
The garbage collector periodically finds variables that are no longer in use at regular intervals, and then releases the memory it occupies.
There are two ways of doing this:
Mark Clear (most commonly used, marked in many ways, the same principle);
Reference counting (easy to cause circular references, especially IE8 and the following JS COM objects!) );
Two. Managing Memory
For security reasons, the general computer system allocates less memory to the Wed browser than the desktop application, so in order to achieve better performance in limited memory, it is possible to use dereference, when a reference to dismiss a value is not to say that the memory occupied by the auto-retract, Instead, the value is detached from the execution environment so that the garbage collector is recycled the next time it runs.
"JS" Performance issues