JavaScript
  Home arrow JavaScript arrow Page 7 - 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 Developerworks
 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

    PCmover - $15 Off with Coupon Code CJPH7Q

    An Object Lesson In JavaScript - Room With A View
    (Page 7 of 9 )

    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


     

       

    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

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




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