Javascript HashMap

Posted by luca
on Monday, October 30

Reading around i've discovered that Javascript associative arrays returns unpredictable results, i.e. length param is not correctly handled.

Array object should be used only with a numeric index and best way to avoid this problem is to use Object.

But, if I wanna put more objects in my object?

Of course i can do this with previous method, but i don't like it :-P. So, i've written a 100% OOP class, that use Prototype and it simulate a java HashMap.

I've also implemented an exception handling.

A little example:

I hope this is useful for you, of course I've attached source code.

Comments

Leave a response

  1. HashMap en Javascript - aNieto2KDecember 16, 2007 @ 04:45 PM
    [...] Es fant?°stico ver gente tan buena y que encima comparte su conocimiento, esta gente de The DigitalConspiracy.net se han currado una versi??n en Javascript del objeto HashMap de Java. [...]
  2. keiDecember 16, 2007 @ 04:45 PM
    Thanks, it's a very useful. But I found that it has a error. returns of containsKeys func. contains aleady removed key. for(var x in this.oStruct){ //add test for invalid key if(this.oStruct[x] != undefined){ returnArray[i] = x; i++; } }