2
我知道,你可以使用下面的types
延長擴展協議JS日期clojurescript
object, array, function, string, nil
即
(extend-type nil Functor
(fmap
([_ _] nil)
([_ _ _] nil)))
我希望爲本地日期對象做同樣的。這是如何完成的?
也..有沒有更多的小寫字母,我錯過了?
我知道,你可以使用下面的types
延長擴展協議JS日期clojurescript
object, array, function, string, nil
即
(extend-type nil Functor
(fmap
([_ _] nil)
([_ _ _] nil)))
我希望爲本地日期對象做同樣的。這是如何完成的?
也..有沒有更多的小寫字母,我錯過了?
下面是如何延長日期對象:
(defprotocol Functor
(fmap [_]))
(extend-type js/Date
Functor
(fmap
([_] (.log js/console 42))))
(fmap (js/Date.)) ;; logs 42
零,字符串,數字陣列,功能,布爾值,默認
來自himera(http://himera.herokuapp.com/synonym.html):
;; In addition native JavaScript objects like
;; Function, Object, Array, Number, String
;; are never actually directly extended
;; For example say you'd like to use RegExps
;; as functions
(extend-type js/RegExp
IFn
(-invoke
([this s]
(re-matches this s))))
(filter #"foo.*" ["foo" "bar" "foobar"])
;; => ("foo" "foobar")
;; This is precisely how callable collections
;; are implemented.