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

Construction Crew - 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
There are a couple of other interesting things about JavaScript objects. For example, should you ever need to, you can obtain complete information on an object's constructor via the "constructor" property. The following example demonstrates how it can be used with the Sumthing object constructor.

<script language="JavaScript">
alpha = new Sumthing(23, 865);
alert("The object constructor for alpha is " + alpha.constructor);
</script>

Here's what it looks like:



And you can use the "prototype" keyword to add new object properties to an already existing object - consider the following addition to the Room object you just saw:
<script language="JavaScript">
// Room object
// accepts area (sq. ft.) and colour (walls) as parameters
function Room(area, colour)
{
this.area = area;
this.colour = colour;
}
Room.prototype.direction = "east";
</script>

This would add an object property named "direction", with value "east" to the Room object constructor. And when you try to access the object property
<script language="JavaScript">
Kitchen = new Room(1000, "green");
alert(Kitchen.direction);
</script>

you should see this:


The "prototype" keyword can be used to add object methods as well - try it yourself and see!

 
 
>>> 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: