The with Statement
Turning back to statements for a short time, the with statement makes using objects in JavaScript easier by reducing the amount of code you have to write.
The with statement enables you to create a default object for a statement, thus simplifying the code and reducing the amount you have to type in.
The following is an example:
<script language="JavaScript"> <!-- Cloaking device on! inp1 = prompt("Enter a number","Number goes here"); inp2 = prompt("Enter a number","Number goes here"); inp3 = prompt("Enter a number","Number goes here"); alert("The largest number entered was " + Math.max(inp1, inp2, inp3)); alert("The smallest number entered was " + Math.min(inp1, inp2, inp3)); // Cloaking device off --> </script>
Using the ...
Get JavaScript™ 1.5 by Example now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.