目前{{compare}}(对于任何非CLJS IComparable类型)类型仅接受原始类型(数字、布尔、字符串、数组)并将它们转发到{{goog.array.defaultCompare}}(它只返回 a > b ? 1 : a < b ? -1 : 0 )。
尽管,标准定义任何具有{{valueOf}}的都可以进行比较
https://mdn.org.cn/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Relational_operators
因为{{valueOf}}应该返回这些原始类型之一。也就是这有效
(let [x0 #js{:x 1, :valueOf #(-> 1)}
x1 #js{:x 2, :valueOf #(-> 2)}
dc garr/defaultCompare]
(list (dc x0 x1) (dc x1 x0) (dc x1 x1)))
我们应该允许这样,即而不是
:else
(if (and (or (string? x) (array? x) (true? x) (false? x))
(identical? (type x) (type y))))
(garray/defaultCompare x y)
(throw (js/Error. (str "Cannot compare " x " to " y))))
do a
(if (and (or (string? x) (array? x) (true? x) (false? x)
(and (js-in "valueOf" x) (js-in "valueOf" y))))
(identical? (type x) (type y))))
(garr/defaultCompare x y)
(throw (js/Error. (str "Cannot compare " x " to " y))))
我们还应该为{{js-in}}提供一个布尔标签。