Is there a way to make another container in cljs like it is in clojure by implementing IDeref?

(reify clojure.lang.IDeref
     (deref [_] ...))

The compiler warns IDeref is not a protocol

有帮助吗?

解决方案

Try this:

(def a
  (reify IDeref
    (-deref [_] "Hello!")))

(.log js/console @a)

outputs "Hello!". You may want to use deftype:

(deftype LikeAtom []
  IDeref
  (-deref [_] "Hello!"))

(.log js/console @(LikeAtom.))
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top