How can I tag methods created with `reify` with ^: export so that the Closure compiler does not rename them?

When creating JavaScript objects with reify , how can I tag methods with ^:export so that the Google Closure compiler doesn't rename them in advanced mode?

For instance:

 (reify Object (foo [this] ...) (bar [this] ...)) 

I tried

 (reify Object (^:export foo [this] ...) (^:export bar [this] ...)) 

but this doesn’t seem to help, and the names are still changing with improved optimizations.

If this is not the case, how can I build a JavaScript object using methods other than creating a simple js-obj and using set! to set functions in properties (where I'm not sure how to prevent advanced optimizations from breaking things)?

+5
source share
1 answer

You must provide ^:export in your protocol methods, since you will call them directly in JS, not in the methods from your reified object.

 (ns example.core) (defprotocol MyProtocol (^:export foo [this]) (defn ^:export create [] (reify MyProtocol (foo [this] "bar"))) 

Then you can use it from JS:

 var a = example.core.create(); var b = example.core.foo(a); // b = "bar" 

I tried it with the current cljs.jar and released optimized JS with the original name foo .

+6
source

All Articles