With in Javascript

Source: Internet
Author: User

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) }

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.