This example describes the use of with functions in JavaScript. Share to everyone for your reference. The specific analysis is as follows:
The WITH function in JavaScript, known as the With statement, can be conveniently used to refer to an existing property in a particular object, but cannot be used to add properties to an object, and you must explicitly reference the object to create a new property.
With function to set the default object for the statement.
With (object)
Statements
Parameters:
Object
The new default object.
Statements
One or more statements, object is the default object for the statement.
Description
The With statement is typically used to shorten the amount of code that must be written in a particular case. In the following example, note the repeated use of Math:
The code is as follows:
x = Math.Cos (3 * Math.PI) + math.sin (math.ln10) y = Math.tan (* math.e)
When you use the WITH statement, the code becomes shorter and easier to read:
The code is as follows:
With (Math) {x = cos (3 * PI) + sin (LN10) y = tan (E)}
Application code Example:
?
1 2 3 4 5 6 |
<script> with (document) write (' filesize= ' +filesize), title= ' I title ', bgcolor= ' teal '; </script> |
I hope this article will help you with your JavaScript programming.