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?
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!
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.
(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 it emitted optimized JS with original foo
name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With