HTML and CSS Reference
In-Depth Information
FORMAT
with (object){
< properties used without the object name and dot>
}
EXAMPLE
with(employee){
document.write(name, ssn, address);
}
EXAMPLE
8.9
<html>
<head><title>The with Keyword</title>
<script type = "text/javascript">
1
function book
(title, author, publisher){
2
this.title = title; //
Properties
this.author = author;
this.publisher = publisher;
3
this.show = show;
//
Define a method
}
4
function show
(){
5
with(this)
{ //
The
with
keyword with
this
6
var info = "The title is " +
title
;
info += "\nThe author is " +
author
;
info += "\nThe publisher is " +
publisher
;
7
alert(info);
}
}
</script>
</head>
<body bgcolor="lightblue">
<script type = "text/javascript">
8
var childbook = new book
("A Child's Garden of Verses",
"Robert Lewis Stevenson",
"Little Brown");
9
var adultbook = new book
("War and Peace",
"Leo Tolstoy",
"Penguin Books");
10 childbook.show(); //
Call method for child's book
11 adultbook.show(); //
Call method for adult's book
</script>
</body>
</html>