set[obj] = true;
This works, up to a point. It works great with string and numbers, but with other objects, they all seem to “hash” to the same value and access the same property. Is there some kind of way I can generate a unique hash value for an object? How do strings and numbers do it, can I override the same behavior?
You could, alternatively, maintain an array which indexes the objects in question, and use its index string as a reference to the object. Something like this:
var ObjectReference = ; ObjectReference.push(obj); set['ObjectReference.' + ObjectReference.indexOf(obj)] = true;
Obviously it’s a little verbose, but you could write a couple of methods that handle it and get and set all willy nilly.
This brings up another interesting point; you can define a toString method on the objects you want to hash, and that can form their hash identifier.