TechieDrill Your World Of Technical Tutorials

Javascript: With Statement

11.13.2009 · Posted in JavaScript
The with statement allows you to access the methods and properties of an object without having
to specify the name of the object on every line.Without the with statement, you will always need to
specify the name of the object you are working on next to every property or method you wish
to access:

With statement allows to access properties of an object without specifying the object with each and every property. By specifying the keyword WITH with the object all the properties of that object can be accessed without specifying the object name for each and every property

For instance

with (document){

write(”This is line 1 <BR>”);

write(”This is line 2 <BR>”);


write(”This is line 3 <BR>”);

write(”This is line 4 <BR>”);

}

NOTE:

The objects set with WITH keyword has scope only inside the curly braces. Objects outside the braces needs to be explicitly mentioned with the object and property names

Leave a Reply

You must be logged in to post a comment.