Home arrow JavaScript arrow Page 7 - An Object Lesson In JavaScript

Room With A View - JavaScript

Think JavaScript is only good for image swaps and flying <div>s?Think again - this article takes an in-depth look at some of theobject-oriented constructs available in JavaScript, and demonstrates howJavaScript objects can substantially speed up code development anddeployment.

TABLE OF CONTENTS:
  1. An Object Lesson In JavaScript
  2. Object Lessons
  3. Sumthing New
  4. Alpha Radiation
  5. Add()ing Some More
  6. Turning Up The Heat
  7. Room With A View
  8. Construction Crew
  9. A Hot Date
By: Vikram Vaswani, (c) Melonfire
Rating: starstarstarstarstar / 23
April 02, 2001

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
Just as you can pass parameters to an object, it's also possible to pass it another object. Consider the following example, which consists of two object constructors - the second one is set up to accept an object as parameter.

<script language="JavaScript">
// Room object
// accepts area (sq. ft.) and colour (walls) as parameters
function Room(area, colour)
{
this.area = area;
this.colour = colour;
}
// House object
// accepts price as parameter
function House(price, room)
{
this.price = price;
this.obj = room;
}
</script>

Here's how you might use it:
<script language="JavaScript">
Kitchen = new Room(500, "white");
DiningRoom = new Room(600, "white");
RedGables = new House(89000, Kitchen);
alert(RedGables.obj.area);
</script>

In this case, the newly-created instance of the Room object, "Kitchen", is passed to the House object "RedGables". Using a hierarchical structure, it is possible to drill down through the House object to the Room object and obtain the value of a specific object property. This is similar to the manner in which many DOM objects are accessed.

 
 
>>> More JavaScript Articles          >>> More By Vikram Vaswani, (c) Melonfire
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

JAVASCRIPT ARTICLES

- Javascript for Beginners: An Introduction
- Introduction to JavaScript
- Adding Elements to a Tree with TreeView jQue...
- Using the Persist Argument in a TreeView jQu...
- Using Unique and Toggle in a TreeView jQuery...
- Using Event Delegation for Mouseover Events ...
- Using the Animate Option in a Treeview jQuer...
- Using HTML Lists with Event Delegation in Ja...
- Opened and Closed Branches on a TreeView jQu...
- Mouseover Events and Event Delegation in Jav...
- Creating a TreeView JQuery Hierarchical Navi...
- Event Delegation in JavaScript
- A Look at the New YUI Carousel Control
- Working with Draggable Elements and Transpar...
- Displaying Pinned Handles with Resizable Con...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: