Hi,
for our MYB project we like to use a hashtable to "centrally" store all information that we get from the web services. A hashtable is in our opinion quite suitable, because you can use keys to store data in a structured manner and to retrieve data quiet easily. Now the issue is that JavaScript offers no real hashtable implementation. The JavaScript Array() can be used with keys, but it is not a real hashtable. Now I found some hashtable implementations on the web, which were coded by private persons. Some of them look quiet code and seem to do the things we need (e.g. this one).
Now I wanted to ask, if anyone of you already has some experience in taking code classes or libraries from the web, that were implemented by "hobby" coders?
André
Comments (2)
Javascript's native Object data type is meant for exactly the situation you describe. You can use Objects just like Arrays, but they hold only the keys you give them (read here for why to use Object instead of Array: http://www.andrewdupont.net/2006/05/18/javascript-associative-arrays-considered-harmful/ )
var data = new Object();
data["key"] = "data value";
Tell me how this is not a hashtable? Why don't you trust the creators of JavaScript to make these operations as fast as possible? They probably base that implementation on a hash table model anyway, so why reinvent the wheel? Use it.
This "Chidambaram" guy is right as well, depending on where you need the data and when, you can decide to store it server-side in a PHP associative array, or client-side in javascript. It all depends on what you need to do with it.
But if you use JavaScript, I assure you, the language is robust and very high-level; don't concern yourself with re-implementing data types it already gives you.
Posted by Tristan | March 16, 2007 2:40 PM
Posted on March 16, 2007 14:40
Personally, I'd say to go with this Tristan guy's suggestion. I do have to say that his reference to Chidambaram is quite humorous.
Posted by Bud Gibson | March 16, 2007 10:26 PM
Posted on March 16, 2007 22:26