[thelist] Proper Way of Separating 'Library' Files in JS

Matt Warden mwarden at gmail.com
Fri Jun 17 10:26:28 CDT 2005


Andrew,

On 6/17/05, Andrew Clover <and-evolt at doxdesk.com> wrote:
> (OT: I'm not sure what you want a hashtable for, isn't JS's built-in
> Object good enough?)

No. In Javascript, all member properties become keys in the hash. It's
possible to try to set a key that collides with a member property
(which therefore is already set in the hash). This has unexpected
results, depending on what browser you are using. In IE, it won't let
you do it for so-called 'built-in' member properties.

Essentially, I am prepending a string to all hash keys to ensure there
are no collisions with member properties. Yes, Object has few
properties, but it's a quick workaround that can avoid potential
problems. Add to that the fact that it is relatively common practice
to add members to Object's prototype so that it is added to all
classes (since Object is the superclass to them all). It's easy to
just avoid potential problems by whipping up a quick data structure.

It's probably the most annoying thing about Javascript, in my opinion.
Whats worse is when people try to use the Array class as an
associative array / hashtable and start getting keys like 'length'
that are really member properties.

Anyway, thanks for the answer to my original question.

-- 
Matt Warden
Miami University
Oxford, OH, USA
http://mattwarden.com


This email proudly and graciously contributes to entropy.


More information about the thelist mailing list