How to use the ES6 hash map on any object without specifying a link (Iehehcode)

I experimented with ES6 Map in io.js and realized that I could not do the following:

var map = new Map()
map.set( {key:"value"}, "some string");
map.get( {key:"value"} ); // undefined. I want "some string"

This is because {key: "value"} === {key: "value"} is false.

I need to be able to use the object as a key, but not require the ACTUAL object to look up a value, for example, how java HashMap uses hashcode and equals. Is it possible?

+2
source share
1 answer
  • If the lack of an object identifier comes from roundize-deserialize roundtrip, just give them a unique identifier that will persist and use that ID as a key
  • , , , .
  • - . , JSON- .
  • JSON-encode get set. JSON- . ,
+6

Source: https://habr.com/ru/post/1599260/


All Articles