/
0707.html
42 lines (38 loc) · 877 Bytes
/
0707.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<HTML>
<HEAD>
<TITLE>Custom objects and associative object arrays</TITLE>
<SCRIPT>
function showProperties (theObject){
for (i in theObject) {
if (theObject[i] != null) {
document.write(i + " : " + theObject[i] + "<br>");
}
else {
document.write(i + "<br>");
}
}
return;
}
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT>
function Rectangle(height, width){
// constructor function
this.height = height;
this.width = width;
}
// create the function
function calc_Area () {
return this.height * this.width;
}
// turn the function into an object method
Rectangle.prototype.calcArea = calc_Area;
// instantiate the object
var theRectangle = new Rectangle (3, 5);
// set an instance property
theRectangle.width = 10;
showProperties (theRectangle);
</SCRIPT>
</BODY>
</HTML>