How to use the with statement in js_javascript skills
May 16, 2016 pm 07:08 PM1) Brief description
The with statement can be conveniently used to reference existing attributes in a specific object, but it cannot be used to add attributes to the object. To create new properties on an object, you must explicitly reference the object.
2) Syntax format
with(object instance)
{
’ s ‐ ‐ ‑ ‑ ‑ ‑ According to the previous writing method, the properties or methods of an object are obtained through: object.property or object.method. It is a bit troublesome to obtain the properties and methods of the object respectively. After learning the with statement, you can use something like the following To achieve this:
with(objInstance)
{
var str = attribute 1;
.....
} eliminates the trouble of writing the object name multiple times.
3) Example
The code execution effect is as follows:
Name: kobe bryant
Age: 28
Gender: boy

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Replace String Characters in JavaScript

HTTP Debugging with Node and http-console

Custom Google Search API Setup Tutorial
