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

 
Developer Updates  
Free Website Content 
IBM Rational Software Development Conference
 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? 
JAVASCRIPT

An Object Lesson In JavaScript
By: Vikram Vaswani, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 21
    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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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

    Route your faxes to your email inbox. Private, secure fax numbers available from CallWave. Choose your fax number.

    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

    - Getting Attention with Interactive Effects
    - Interacting with Tooltips and Previews
    - Just-in-Time Information and Ajax
    - Interactive Effects
    - Using Cookies With JavaScript
    - Understanding the JavaScript RegExp Object
    - Controlling Browser Properties with JavaScri...
    - Using Timers in JavaScript
    - Form Validation with JavaScript
    - JavaScript Exception Handling
    - Stringing Things Along
    - Understanding The JavaScript Event Model (pa...
    - Understanding The JavaScript Event Model (pa...
    - An Object Lesson In JavaScript




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway