When the execution flow enters any of the following statements, the scope chain will be extended:
* 1) Catch Block of the try-catch statement
* 2) with statement
These two statements Add a variable object at the front end of the scope chain. For with, its variable object contains all the attributes of the specified object and the variable declaration made by the method; for catch, its variable object contains the declaration of the thrown error object. These Scalar objects are read-only. Therefore, variables declared in the with and catch statements are added to the variable objects in the execution environment.
With will add the parameter object to the execution environment of the {} code block (Execution
The scope chain header in context modifies the order of index objects.
with (object) statements
Parameters
Object: new default object.
Statements: one or more statements, Object
Is the default object of the statement.
Description
The with statement is usually used to shorten the amount of code that must be written in a specific situation. In the following example, pay attention to the reuse of Math:
x = Math.cos(3 * Math.PI) + Math.sin(Math.LN10) y = Math.tan(14 * Math.E)
When the with statement is used, the Code becomes shorter and easier to read:
with (Math){ x = cos(3 * PI) + sin (LN10) y = tan(14 * E) }