我正在调用一个具有三个参数的 native 函数:nativeFunction(success, error, options);
成功回调
,一个函数。函数{console.log(s);}
错误回调
,一个函数。function(e) {console.log(e);}
- 选项(如果重要)JSON 映射
我有一个像这样的公共(public) ClojureScript 函数,包装了调用:
;; this works but I can't separate the success from the failure
(defn ^:export publicFn [cb]
(nativeFunction. cb cb #js {}))
;; this doesn't work
(defn ^:export publicFn [cb]
(nativeFunction. (partial cb js/undefined) cb #js {}))
所以应该这样调用:myNs.publicFn(function(e, s) {console.log(e, s);});
。
换句话说,我希望能够将 ClojureScript 中的两个处理程序约定转换为第一个错误参数约定,同时与 Javascript 兼容。
可能吗?
最佳答案
嗯,我一定运行了一些其他代码,或者可能存在冲突,因为以下解决方案有效:
(defn ^:export publicFn [cb]
(nativeFunction. (partial cb js/undefined) cb #js {}))
我可以像这样从#js(错误的JavaScript)调用它:
myFn(function(e, d) { console.log(e, d); } );
关于javascript - Clojurescript - #js 的部分函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32057955/