[英]Accessing defrecord methods in ClojureScript Figwheel
I have some code in cljc files which compiles to both Clojure and ClojureScript. 我在cljc文件中有一些代码可以编译成Clojure和ClojureScript。
in protocols.cljc 在protocols.cljc中
(defprotocol Transformable ".."
(scale [this scalar] "" ) ...)
in pattern.cljc 在pattern.cljc中
(defrecord APattern [paths]
Transformable
(scale [this s] (...)) ...)
in another.cljc 在another.cljc
(defn f [pattern] (.scale pattern (/ 1 2)) )
And in core.cljs 并在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 检查core.cljs中的模式对象的字段(使用js-keys)向我显示该对象有一些叫做的东西
"patterning$protocols$Transformable$scale$arity$2"
which looks like my function. 看起来像我的功能。 So am I just doing something wrong to access it in ClojureScript? 所以我只是在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: 所以你的f
函数应该如下所示:
(require 'protocols)
(defn f [pattern] (protocols/scale pattern (/ 1 2)) )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.