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

Sumthing New - 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
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
 

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: