www.pickatutorial.com Computer Tutorials
Top eBooks: C/C++ | C# | Android | Mathematics | Database | Cloud | Graphics | Networking | Oracle | Hardware | AI
Top Tutorials: C/C++ | C#.NET | PHP MySQL | Java | Java Script | jQuery | HTML | xHTML | HTML5 | VB Script| CSS
Lessons JavaScript with statement Bookmark and Share
Tutorial Home
Lesson 1
Lesson 2
Lesson 3
Lesson 4
Lesson 5
Lesson 6
Lesson 7
Lesson 8
Lesson 9
Lesson 10
Lesson 11
Lesson 12
Lesson 13
Lesson 14
Lesson 15
Lesson 16
Lesson 17
Lesson 18
Lesson 19
Lesson 20
Lesson 21
Lesson 22
Lesson 23
Lesson 24
Lesson 25
Lesson 26
Lesson 27
Lesson 28
Lesson 29
Lesson 30
Lesson 31
Lesson 32
Lesson 33
Lesson 34
Lesson 35
Lesson 36
Lesson 37
Lesson 38
Lesson 39
Lesson 40
Lesson 41
Lesson 42
Lesson 43
Lesson 44
Lesson 45
Lesson 46
Lesson 47
Lesson 48
Lesson 49

With the with statement of JavaScript we can simplify some of our type related code.

When working with types / objects in JavaScript, we need to set their properties and some of the object have many many of them. On each property set we need a reference to the type. In such situations the use of the with statement simplifies our job. The with statement allows us to reduce the type references from many to just one.

Tye syntax of using the with statement follows:

with (variableName)
{
//we do not need the variableName here to refer to its properties and / or
// its functions. The variableName is always implied within the with block
}

We type with followed by a type / variable name, surrounded within a pair of parenthesis, followed by a pair of braces { }. We write the type specific code within the pair of braces. Within the pair of braces we do not need to refer to the variableName, it is always implied.

Code example follows:

<script type="text/JavaScript">
str = "Hello World ";
with (str)
{
document.write("The string is of " + length + " characters and ")
document.write("in upper case it's: " + toUpperCase())
}
</script>


Next >>> Lesson No. 38: JavaScript Ternary (?) Operator





Home - Advertise - Contact - Disclaimer - About Us
© Since 2006 pickatutorial.com -- All Rights Reserved.