Does ClojureScript have the same pitfalls? In cljs, Date equality checks are by value. However, other checks (
The following isn’t necessary to know, but it does provide some interesting details, depending on your definition of “interesting.”
So how does ClojureScript handle Date comparison?
The ClojureScript equality check we care about is:
Date objects implement the
IEquiv protocol, which is where we can find the implementation of
-equiv. (Side note: the
- at the start of the function name is a signal that this is a protocol method.) When we compare Date objects, we’re calling
We can see that, in the end, we’re comparing values via
But, if we try to compare dates via
The comparison functions
For those interested in the cljs compiler, following
::ana/numeric to figure out how the type checks are done might be a worthwhile endeavor.
Find this post useful? Share the love! Tweet