Is there a way to give objects in js custom hashes, just as overriding
__hash__()
in python let’s someone define how a given object is hashed into a dictionary.
My underlying question is: what hash function is used to put js objects into associative arrays, and can I over-ride it?
You mean using objects as keys, how do you make sure you access that key again?
The magic method is
toString(). Turns out all objects in JS use string keys, and thetoString()method is called if it’s not a string.http://jsfiddle.net/udsdT/1/
Usually though, you really don’t want to use whole objects as keys. Especially if you dont create your own
toString()method, since the defaulttoString()method on basic objects isn’t exactly very awesome…