By nerdyhearn
via nerdyhearn.com
Published: Aug 11 2008 / 15:08
A simple implementation of a Hashtable in javascript.
Tweet
SaveShareSend
Tags: how-to, javascript, methodology



Comments
kdavies replied ago:
"Javascript does not have a native type that is comparable to a Hashtable"
Umm, yes it does? All objects in javascript are pretty much hashtables.
nerdyhearn replied ago:
No, it doesn't. "All objects in javascript are pretty much hashtables" -- So where are the getters and setters? Where are the abilities to list all keys natively? I don't see any functionality that allows a user to access a Javascript table as you would in Java.
richmarr.wordpress.com replied ago:
If you want to convince people your solution is valuable, the only way to do it is to show them the benefit over the conventional methods, otherwise you just sound like you don't know the conventional methods.
wekempf replied ago:
Not to mention his "solution" isn't what he claims it to be. It's NOT a Hashtable. It's an associative container, yes, but a very poor one (O(n) lookup time?), and NOT a _Hash_ table.
richmarr.wordpress.com replied ago:
I'd also recommend against casual use of exceptions in browser-based Javascript. The code required can be cumbersome and is often unnecessary. Compare the two following examples.
Your code is less concise (hence less readable, and slower to download) than the native non-exception-based solution:
cowardlydragon replied ago:
Oh Jesus, where to begin.
Dude, you're using Javascript. Loose typing. More compact syntax.
Getters and Setters are an aspect of Java's pseudo-strong typing.
Getter in JS: someobject[somekey]
Setter in JS: someobject[somekey] = somevalue
Voters For This Link (6)
Voters Against This Link (11)