[英]Calling JavaScript object property as a constructor from ClojureScript
[英]How to declare javascript object with constructor in clojurescript
我的代碼與領域庫一起使用,並在某些時候調用領域構造器:
(dependencies/realm. (clj->js options))
Realm的聲明如下:
(def realm (js/require "realm"))
現在,我想臨時模擬領域對象,以不調用庫。 我嘗試了這種方法:
(def realm #js {:schemaVersion (fn [])
:close (fn [])})
它對於模擬close()和schemaVersion()函數效果很好,但是我遇到了錯誤dependencies.realm is not a constructor
。realm dependencies.realm is not a constructor
。
如何將構造函數聲明添加到領域對象占位符?
謝謝。
在javascript中,構造函數是一個函數。 相反,您應該具有一個返回對象的函數:
(def realm (fn [] #js {}))
我假設schemaVersion
和close
是靜態方法。 您可以稍后添加它們:
(goog.object/extend realm #js {:schemaVersion (fn [])
:close (fn [])})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.