• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 8. JavaScript Object-Oriented Pr... > Object-Oriented Programming in JavaS...

Object-Oriented Programming in JavaScript

One way to think of JavaScript objects is as associative arrays. From our discussion of arrays and using the for / in statement to pull information from objects, you might have already suspected as much. To demonstrate this fact, the following script builds an object, assigns data to it, and then pulls it apart as an array:

<html> 
<head> 
<title>Associative Array</title> 
<script language="JavaScript"> 
var tree = new Object(); 
tree.size="Big and taller than Uncle Jim."; 
tree.shade="It keeps us cool in the summer"; 
tree.fall="We make giant leaf pumpkins." 
var display =tree["size"] + "<br>"; 
display +=tree["shade"] + "<br>" 
display +=tree["fall"] 
document.write(display); 
</script> 
</head> 
<body bgcolor="wheat" > 
</body> 
</html> 


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint