How to customize object equality for JavaScript Set

后端 未结 9 1362
臣服心动
臣服心动 2020-11-22 16:48

New ES 6 (Harmony) introduces new Set object. Identity algorithm used by Set is similar to === operator and so not much suitable for comparing objects:

9条回答
  •  误落风尘
    2020-11-22 17:07

    To add to the answers here, I went ahead and implemented a Map wrapper that takes a custom hash function, a custom equality function, and stores distinct values that have equivalent (custom) hashes in buckets.

    Predictably, it turned out to be slower than czerny's string concatenation method.

    Full source here: https://github.com/makoConstruct/ValueMap

提交回复
热议问题