简体   繁体   中英

Accessing defrecord methods in ClojureScript Figwheel

I have some code in cljc files which compiles to both Clojure and ClojureScript.

in protocols.cljc

(defprotocol Transformable ".." 
    (scale [this scalar] "" ) ...)

in pattern.cljc

(defrecord APattern [paths]
    Transformable
      (scale [this s] (...)) ...)

in another.cljc

(defn f [pattern] (.scale pattern (/ 1 2)) )

And in core.cljs

(another/f pattern)

However, I'm getting an error on the browser console

TypeError: pattern.scale is not a function

Checking the fields of pattern object in core.cljs (using js-keys) shows me that the object has something called

"patterning$protocols$Transformable$scale$arity$2"

which looks like my function. So am I just doing something wrong to access it in ClojureScript? Does . notation not work? Do I need to do something else?

Calls to protocol functions are just like calls to any other function. So your f function should look like:

(require 'protocols)
(defn f [pattern] (protocols/scale pattern (/ 1 2)) )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM