Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0
This is the forum to discuss the Wrox book Professional JavaScript for Web Developers by Nicholas C. Zakas; ISBN: 9780764579080
Welcome to the p2p.wrox.com Forums.

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 .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 5th, 2006, 03:54 AM
Registered User
Join Date: Jun 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default associative arrays as objects left out

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.

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

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)
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP array_push() for associative arrays mcmahonc Beginning PHP 1 January 9th, 2010 01:13 PM
array of arrays-objects joker Java Basics 1 February 11th, 2007 09:12 PM
Associative arrays not shown at book brasilino BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 1 December 16th, 2006 08:51 AM
Receiving associative arrays chrscote Classic ASP Basics 0 June 14th, 2005 12:38 PM
Removing an Element from an Associative Array nick8245 Javascript 2 September 26th, 2003 12:15 PM

All times are GMT -4. The time now is 10:28 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.