You are currently viewing the BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .

Throughout chapter 3 (object basics), you extensively use "var o = new ClassName();" as a way of creating classes, however only until chapter 6 (DOM basics) do you give us a glimpse of how to create associative arrays (i.e. hashes) with the "checking the Node type" section.

I am a bit confused... Is the associative array way of creating and accessing properties a non-standard approach in OO in JavaScript? It's very Perlish, and a more elaborate explaination of for/against this approach would be most appreciated.

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).