diegoles / closure-library

Automatically exported from code.google.com/p/closure-library
0 stars 0 forks source link

goog.structs.Map uses toString to define object identity #541

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
goog.structs.Map uses toString to define object identity, making it difficult 
to store complex complex objects.

This example is silly, but my point is that it would be desirable to be able to 
use something other than conversion to a string to define an object's identity 
(e.g. obj.hash if it exists with '===' or obj.equals if it exists, which Map 
even defines in its prototype).

What steps will reproduce the problem?

var m = new goog.structs.Map()
undefined
var x = { x : 'x' }
undefined
var y = { y : 'y' }
undefined
y.toString = function(){return 'key'}
function (){return 'key'}
x.toString = function(){return 'key'}
function (){return 'key'}
m.set(x,"value1")
undefined
m.set(y,"value2")
undefined
m.get(y)
"value2"
m.get(x)
"value2"

What is the expected output? What do you see instead?

I would want:
m.get(y)
"value1"
m.get(x)
"value2"

But I get:
m.get(y)
"value2"
m.get(x)
"value2"

What version of the product are you using? On what operating system?
git master HEAD

Please provide any additional information below.

Note: we cannot accept patches without the contributor license agreement
being signed. See http://code.google.com/p/closure-
library/wiki/Contributors for more info.

Original issue reported on code.google.com by jamie.f....@gmail.com on 21 Feb 2013 at 8:50