![](/img/trans.png)
[英]How i can mark function as “private” to renaming it by Google Closure Compiler?
[英]How can I mark methods created with `reify` with ^:export, so that the Closure compiler doesn't rename them?
使用reify
创建JavaScript对象时,如何使用^:export
标记方法,以便Google Closure编译器不会在高级模式下重命名它们?
例如:
(reify
Object
(foo [this] ...)
(bar [this] ...))
我试过了
(reify
Object
(^:export foo [this] ...)
(^:export bar [this] ...))
但这似乎没有帮助,并且名称仍然会随着高级优化而改变。
如果没有办法做到这一点,我怎么能用方法构造一个JavaScript对象,而不是创建一个普通的js-obj
并使用set!
将函数设置为属性(我不知道如何防止高级优化破坏事物)?
您必须在协议方法上提供^:export
,因为您将在JS中调用它们,而不是直接从您的实现对象中调用方法。
(ns example.core)
(defprotocol MyProtocol
(^:export foo [this])
(defn ^:export create []
(reify
MyProtocol
(foo [this] "bar")))
然后你可以在JS中使用它:
var a = example.core.create();
var b = example.core.foo(a);
// b = "bar"
我用当前的cljs.jar尝试了它,它发出了原始foo
名称的优化JS。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.