JavaScript
  Home arrow JavaScript arrow Page 3 - An Object Lesson In JavaScript
FaxWave - Free Trial.
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 
 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
     
     
    Iron Speed
     
    ADVERTISEMENT

    PCmover - $15 Off with Coupon Code CJPH7Q

    An Object Lesson In JavaScript - Sumthing New
    (Page 3 of 9 )

    You've probably already used JavaScript objects before - for example, the code
    <script language="JavaScript">
    a = new Image();
    </script>
    

    creates a new instance of the Image object, while
    <script language="JavaScript">
    x = new Date();
    </script>
    

    creates a new instance of the Date object.

    JavaScript comes with numerous built-in objects, each with pre-defined methods and properties...but what if you want to roll your own?

    Well, it isn't very difficult - as a matter of fact, it's almost identical to writing a JavaScript function.
    <script language="JavaScript">
    // object constructor
    function Sumthing() {
    }
    </script>
    

    You can create an instance of the Sumthing object like this:
    <script language="JavaScript">
    // object instance
    obj = new Sumthing();
    </script>
    

    Note the all-important "new" keyword - this is how JavaScript knows that you're trying to create an instance of an object, rather than merely running a function.

    The code above creates an instance named "obj" of the object Sumthing. You can verify that it is indeed an object, oh yes, by popping up an alert().
    <script language="JavaScript">
    obj = new Sumthing();
    alert(obj);
    </script>
    

    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

    Iron Speed
     
    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 1 hosted by Hostway