★ wanayoo — archive 1999 http://javascript.about.com/compute/javascript/library/weekly/aa100599.htmNouvelle recherche | Portail wanayoo
Enter Sweepstakes! · Advertise on this site · Get Bargains
About.com  
You are here:  About > Computing/Technology > Focus on JavaScript
An About.com Site
   About.com
 
 One of Over 700 Sites
Your Guide with Guide
Nate Kassebaum
Bio | Contact

Subjects
Compatibility
Reference
Animation Scripts
Cookie Scripts
Image Scripts
Text Scripts
Frame Scripts
Form Scripts
HTML Scripts
Navigation Scripts
Password Scripts
Time Scripts
Window Scripts
Software
Beginner Tutorials
Cookie Tutorials
Image Tutorials
Text Tutorials
Form Tutorials
Frame Tutorials
Multimedia
Navigation Tutors
Time Tutorials
Handling Variables
Window Tutorials

Subject Library 

All articles on this topic

Bookstore
Find books related to this topic Click Here

Videostore
Find videos related to this topic Click Here

ShoppingAbout
Your favorite products, right here Click Here

Stay up-to-date!
Subscribe to our newsletter.

Do you like our sites?
Wish to share them with others - and earn money?
Become an Affiliate

Luna Network
Apply to become
a partner
for this site.
Search for 
in   Sites A to Z
 
 

JavaScript Objects

Dateline: 10/05/99

Many programming languages are what we call "Object Oriented."  This means that you can create your own custom groupings of functions and data in a way that makes sense to your programming approach.

To illustrate what I'm talking about, you could create define a type of object (often called a "class") for an employee of a company.  This definition might include variables for salary, time with the company, job title, social security number, etc.  You may also want to define some functions that apply to an employee; maybe a function to write a paycheck, promote the employee, or whatever.

If you've used object oriented languages like C++ or Java, you're probably following me here without difficulty.  If not, read on: everything will become clear.

JavaScript isn't exactly Object Oriented like C++ or Java.  JavaScript is referred to as "Object-Based."  This means that you can't define object types quite like you would in an object oriented language, but you can still take advantage of most of the object functionality.

To define an object type in JavaScript, you must define it as a function.  You can use the "this" keyword to assign variables and initial values (for the programming savvy, this is like using constructors in object oriented languages).

function Employee()
{
 this.Salary = 0;
 this.TimeEmployed = 0;
 this.JobTitle = "";
 this.SocialSecurity = "";
}

To create this object (called an "instance" of the object), use the "new" keyword.

var John = new Employee();

Now you can work with the values of each employee separately.

John.Salary = 100000;
John.TimeEmployed = 10;
John.JobTitle = "CEO";
John.SocialSecurity = "123-45-6789";

var Mary = new Employee();
Mary.Salary = 75000;
Mary.TimeEmployed = 5;
Mary.JobTitle = "JavaScript Programmer";
Mary.SocialSecurity = "987-65-4321"

To see a brief example of JavaScript objects in action, visit my Very Simple Airline Reservation System.

Visit the message boards!

Previous Features

Enter an email address to send this page:
 
More Options
 
 Advertising
AllBusiness.com
Create your business plan. Here’s how.

Casino Online
Act NOW for 20% Cash Bonus $$

HotJobs.com
Better Jobs for a Better Life

ShopNow
Over 40,000 merchants in one place!

single pixel
single pixel
Marketplace
register domains
get a website$499
long distance deal
business products
0% intro apr
great dsl deal
high paying jobs
quick jobs search
findausedcar
activity planning
build a business
shop around!
$50 off mp3 player
register a domain

 
Related sites
single pixel
on About 
Focus on Java
Focus on Web3D
HTML
Perl
Personal Web Pages
Web Design
XML


Explore More On The About.com Network
Search
Arts/Humanities ·  Autos ·  Cities/Towns ·  Comedy ·  Computing/Technology ·  Cultures ·  Education ·  Food/Drink ·  Gadgets ·  Games ·  Health/Fitness ·  Hobbies ·  Home/Garden ·  Homework Help ·  Industry ·  Internet/Online ·  Jobs/Careers ·  Kids ·  Money ·  Movies ·  Music/Performing Arts  ·  News/Issues ·  Parenting/Family ·  People/Relationships ·  Pets ·  Recreation/Outdoors ·  Real Estate ·  Religion/Spirtuality ·  Science ·  Shopping ·  Small Business ·  Sports ·  Style ·  Teens ·  Travel ·  TV/Radio · 
 
single pixel

For more information, visit
About Us, Be a Guide, or Advertise. For rules of use,
read our User Agreement and
Privacy Policy.

Having a problem?
Report it here.

 © 2000 About.com, Inc. All rights reserved.