Javascript with statement usage _ javascript skills

Source: Internet
Author: User
Js with statement usage method 1) Brief Description
The with statement can be easily used to reference the existing attributes of a specific object, but cannot be used to add attributes to the object. To create a new property for an object, you must explicitly reference the object.

2) syntax format
With (object instance)
{
// Code block
}
Sometimes, in a program code, I need to use the attributes or methods of an object multiple times. According to the previous method, all objects are written through: object. attribute or object. using this method to obtain the attributes and methods of the object is a bit difficult. after learning the with statement, you can implement it in a similar way as follows:
With (objInstance)
{
Var str = attribute 1;
.....
} It is difficult to write object names multiple times.

3) Example

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.