我正在尝试将以下JavaScript函数定义转换为ClojureScript无效:
chrome.webRequest.onBeforeRequest.addListener(
callback_function,
{urls: ["<all_urls>"]},
["blocking"]);
这是我用来尝试复制它的ClojureScript:
(defn my-listener
[data]
(.log js/console data))
(defn web-request
[listener]
(.. js/chrome -webRequest -onBeforeRequest (addListener listener) (clj->js {"urls" ["<all_urls>"]}) (clj->js ["blocking"])))
(web-request my-listener)
看起来函数声明的最后两个部分没有正确生成({urls: ["<all_urls>"]}, ["blocking"]
位)。以下是编译器从ClojureScript版本输出的内容:
example.core.my_listener = function example$core$my_listener(data) {
return console.log(data)
}
;
example.core.web_request = function example$core$web_request(listener) {
return chrome.webRequest.onBeforeRequest.addListener(listener).clj__GT_js(new cljs.core.PersistentArrayMap(null ,1,["urls", new cljs.core.PersistentVector(null ,1,5,cljs.core.PersistentVector.EMPTY_NODE,["\x3call_urls\x3e"],null )],null )).clj__GT_js(new cljs.core.PersistentVector(null ,1,5,cljs.core.PersistentVector.EMPTY_NODE,["blocking"],null ))
}
;
example.core.web_request.call(null , example.core.my_listener);
任何建议将不胜感激。谢谢!
答案 0 :(得分:0)
你的addListener方法/函数/ prototype_inheritance_thing是一个arity三个过程,因此你必须像这样调用它:
(defn web-request
[listener]
(.. js/chrome -webRequest -onBeforeRequest (addListener listener (clj->js {"urls" ["<all_urls>"]}) (clj->js ["blocking"]))))