spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / javascript / diaries / 6

[next]

Web Project Manager
Aquent
US-PA-Collegeville

Justtechjobs.com Post A Job | Post A Resume
Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source

The JavaScript Diaries: Part 6

  1. Introduction
  2. Data Types & Variables
  3. Operators
  4. Functions
  5. Conditional Statements and Loops
  6. Objects
  7. Browser-Based Objects
  8. Window Methods
  9. Window Event Handlers
  10. Navigator, Screen, History and Location Objects
  11. Arrays: Part 1 - Introduction
  12. Arrays: Part 2 - Multiple Array Types
  13. Arrays: Part 3 - Array Properties and Methods
  14. The Math Object
  15. The Date Object

By 

This week we are going to go a little deeper into our study, a process that will last for several weeks. I want to make sure you fully grasp this subject as it's a very important topic, but it can be challenging to understand in the beginning. Take your time, read carefully, and contemplate what you've learned. Eventually, you'll gain an understanding.

JavaScript Objects

As I mentioned in the first installment, JavaScript is an object-based scripting language. This means that the JavaScript interpreter sees the existing data structure as objects rather than a bunch of scattered, random items. As defined by Webopedia an object is "generally, any item that can be individually selected and manipulated.... In object-oriented programming, for example, an object is a self-contained entity that consists of both data and procedures to manipulate the data." Objects can refer to HTML elements, certain parts of the browser, and often refer to custom-made objects. For the most part, the code that is written is used to control objects.

In an object, related properties and methods are grouped into a single package, hence the term "object." Like a function, an object allows you to organize related items within a script. In fact, a function is an object and can be thought of as a 'thing.' A good example of this is a car, which is an object and a thing. An example of an object is:

  function getObject(param1,param2,param3) {
    this.param1=param1;
    this.param2=param2;
    this.param3=param3;
  }

Object Properties

An object has properties. A property is a component or part of the object. Using the above example, a car's properties may include a radio and tires. Properties are data containers, just like variables. Besides being a part of an object, they also give information about the object. One important difference is that properties give information about the window object whereas variables do not. An object holds properties that can be accessed from the outside for use in the overall script.

The properties of an object are accessed through the use of a dot operator. The format would be the name of the object, followed by the dot operator, followed by the property you are trying to access: car.radio and car.tires. You can even go to deeper and obtain further properties, such as: car.cdplayer.speakers.wires.

Object Methods

An object can also have methods. A method does something to the object or with the object, just like the car, which can go forward and backward. A method may cause a new browser window to open, or it may cause text to be selected. Methods use parentheses just like functions, i.e. mainObject.getPrice(). A main difference, however, is that methods can act on a window object whereas functions cannot. According to Core JavaScript Guide 1.5: "A method is a function associated with an object. You define a method the same way you define a standard function."

Review

Let's review what we've just covered. An object is a thing, a collection of properties grouped together. Properties are individual parts of the object. A method is something that causes the object to do something. It may help to think of objects and properties as nouns and methods as verbs.

Now, let's take a look at objects in greater detail. First, we'll look at how to create your own. Later, we'll look at the ones that are built into the JavaScript language.

home / programming / javascript / diaries / 6

[next]

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Whitepapers and eBooks

Symantec Whitepaper: Converging System and Data Protection for Complete Disaster Recovery
Intel Whitepaper: Comparing Two- and Four-Socket Platforms for Server Virtualization
IBM Solutions Brief: Go Green With IBM System xTM And Intel
HP eBook: Simplifying SQL Server Management
IBM Contest: Are You the Next Superstar? Join the "Search for the XML Superstar" Contest to Find Out
Intel PDF: Quad-Core Impacts More Than the Data Center
Intel PDF: Virtualization Delivers Data Center Efficiency
Go Parallel Article: PDC 2008 in Review
Avaya Article: Communication-Enabled Mashups: Empowering Both Business Owners and IT
Intel Whitepaper: Building a Real-World Model to Assess Virtualization Platforms
PDF: Intel Centrino Duo Processor Technology with Intel Core2 Duo Processor
Microsoft Article: Build and Run Virtual Machines with Hyper-V Server 2008
  Go Parallel Article: Q&A with a TBB Junkie
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
IBM eBook: The Pros and Cons of Outsourcing
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Symantec Whitepaper: Comprehensive Backup and Recovery of VMware Virtual Infrastructure
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Fixing MySQL Replication · Firewall Guide: First Steps to Securing the Enterprise · VoxOx Tames the Tumultuous Communications Tangle

Created: July 1, 2005

URL: