New ES 6 (Harmony) introduces new Set object. Identity algorithm used by Set is similar to
var set = new Set();
console.log([...set.values()]); // Array [ Object, Object ]
Set object does not have any compare methods or custom compare extensibility.
.delete() methods work only off it being the same actual object or same value for a primitive and don't have a means to plug into or replace just that logic.
You could presumably derive your own object from a
Set and replace
.delete() methods with something that did a deep object comparison first to find if the item is already in the Set, but the performance would likely not be good since the underlying
Set object would not be helping at all. You'd probably have to just do a brute force iteration through all existing objects to find a match using your own custom compare before calling the original
Here's some info from this article and discussion of ES6 features:
5.2 Why can’t I configure how maps and sets compare keys and values?
Question: It would be nice if there were a way to configure what map keys and what set elements are considered equal. Why isn’t there?
Answer: That feature has been postponed, as it is difficult to implement properly and efficiently. One option is to hand callbacks to collections that specify equality.