September 26, 1999 - Avoid Repeating Object References | WebReference

September 26, 1999 - Avoid Repeating Object References

Yehuda Shiran September 26, 1999
Avoid Repeating Object References
Tips: September 1999

Yehuda Shiran, Ph.D.
Doc JavaScript

JavaScript is an object-based language. Heavily object-dependent statements are often hard to read and understand, but JavaScript's with operator can simplify your statements. The general syntax of this construction is:

with (object) {
  statements
}
When JavaScript encounters an otherwise-unknown identifier inside a with statement, it tries to build a reference out of the object specified as its parameter and that unknown identifier. Take a look at the following demonstration:

with (document) {
  write("There are " + forms.length + " in this document.<BR>");
  writeln("This is a simple example.");
}