nha nha - 4 months ago 20
Javascript Question

call ClojureScript from Javascript

How to call ClojureScript code from Javascript (not the other way around !).

It is already possible to call Clojure from Java, but I don't know how to do the equivalent in ClojureScript.

Answer

Export the functions you want to have available in js by using ^:export, then simply call it as my.ns.fn()

cljs:

(ns hello-world.core)

(defn ^:export greet [] "Hello world!")

js:

hello_world.core.greet()

See the accepted answer to "Clojurescript interoperability with JavaScript" for detailed info.