View Single Post
  #2 (permalink)  
Old June 5th, 2006, 01:37 PM
nzakas's Avatar
nzakas nzakas is offline
Wrox Author
 
Join Date: Dec 2004
Location: Peabody, MA, USA.
Posts: 217
Thanks: 0
Thanked 5 Times in 5 Posts
Default

You raise a good point, perhaps the introduction of associative arrays should come with the discussion of object basics. It's not by any means a non-standard approach since it's a very widely used part of the language. It's all up to your particular requirements.

If you want to create a single instance of an object with no plans of creating more instances, then object literals (associative arrays) are perfectly fine to use. Keep in mind that object literals still inherit from Object, so you'll still get all the properties and methods.

The main drawback is that you lose the ability to create multiple instances and to use prototypes to inherit behavior should you want to extend that object (which may not matter if you really only need one instance).

Nicholas C. Zakas
Author, Professional JavaScript for Web Developers (ISBN 0764579088)
http://www.nczonline.net/
Reply With Quote