JavaScript
  Home arrow JavaScript arrow Page 8 - An Object Lesson In JavaScript
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
JAVASCRIPT

An Object Lesson In JavaScript
By: Vikram Vaswani, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 22
    2001-04-02


    Table of Contents:
  • An Object Lesson In JavaScript
  • Object Lessons
  • Sumthing New
  • Alpha Radiation
  • Add()ing Some More
  • Turning Up The Heat
  • Room With A View
  • Construction Crew
  • A Hot Date

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    An Object Lesson In JavaScript - Construction Crew
    ( Page 8 of 9 )

    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
     

       

    JAVASCRIPT ARTICLES

    - 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...
    - Building Resizable Containers with the Ext J...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek