Applications of with statements in js

Source: Internet
Author: User
In js, The with statement is used to set the code scope to a specific object. It can easily reference existing attributes in the object, but cannot add attributes. Syntax format: with (expression) statement & amp; nbsp;

In js, The with statement is used to set the code scope to a specific object. It can easily reference existing attributes in the object, but cannot add attributes. The syntax format is as follows:

With (expression) statement

 

You need to use the attributes or methods of an object multiple times. As previously written, all objects are passed through: object. attribute or object. methods to obtain the attributes and methods of this object. If you are too troublesome, you can use the with statement!

The js Code is as follows:


Script with (document) {write ("this is a php point-to-point tutorial
"); Write (" php point-to-point URL: www.phpddt.com ");} script

The above js Code runs as follows:


This is a php point-to-point tutorial. The php point-to-point URL is www.phpddt.com.

The with statement is as follows:

Inside the code block of the with statement, each variable is considered as a local variable. If the definition of this variable cannot be found in the local environment, the system queries whether the document object has an attribute with the same name, if any, the document Object attribute value is used as the variable value. Note that it is best to use the with statement less frequently because it is inefficient and inconvenient for code debugging!

 

Related Article

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.