[英]How can I mark methods created with `reify` with ^:export, so that the Closure compiler doesn't rename them?
When creating JavaScript objects with reify
, how can I mark the methods with ^:export
so that the Google Closure compiler doesn't rename them in advanced mode? 使用reify
创建JavaScript对象时,如何使用^:export
标记方法,以便Google Closure编译器不会在高级模式下重命名它们?
For example: 例如:
(reify
Object
(foo [this] ...)
(bar [this] ...))
I've tried 我试过了
(reify
Object
(^:export foo [this] ...)
(^:export bar [this] ...))
but this doesn't seem to help, and the names still get changed with advanced optimizations. 但这似乎没有帮助,并且名称仍然会随着高级优化而改变。
If there isn't a way to do this, how can I construct a JavaScript object with methods, other than creating a plain js-obj
and using set!
如果没有办法做到这一点,我怎么能用方法构造一个JavaScript对象,而不是创建一个普通的js-obj
并使用set!
to set functions to properties (where I'm not sure how to prevent advanced optimizations from breaking things either)? 将函数设置为属性(我不知道如何防止高级优化破坏事物)?
You have to provide ^:export
on your protocol methods as you will call them in JS, not methods from your reified object directly. 您必须在协议方法上提供^:export
,因为您将在JS中调用它们,而不是直接从您的实现对象中调用方法。
(ns example.core)
(defprotocol MyProtocol
(^:export foo [this])
(defn ^:export create []
(reify
MyProtocol
(foo [this] "bar")))
Then you can use it from JS: 然后你可以在JS中使用它:
var a = example.core.create();
var b = example.core.foo(a);
// b = "bar"
I tried it with the current cljs.jar and it emitted optimized JS with original foo
name. 我用当前的cljs.jar尝试了它,它发出了原始foo
名称的优化JS。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.