|
|
|
|
|
by aaco
3748 days ago
|
|
Google Closure Library does this in goog.structs.Set with an interesting generic solution. A string key for the underlying map is generated based on the data type of the element being added in the set. If you're adding an object into the set, the object is mutated so that it stores a unique ID. The object's unique ID is used to form the string key that will identify this object in the set. Note how goog.structs.Set.getKey_ is used in the add() method:
https://github.com/google/closure-library/blob/v20160125/clo... This is how the library obtains the unique ID of an object:
https://github.com/google/closure-library/blob/v20160125/clo... |
|
Also, if this was being done for ES5+ code, then either setting that property to non-enumerable or using something like Symbols would be cool since it would hopefully have a reduced impact on other code.