This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-10-27
Channels
- # announcements (10)
- # beginners (95)
- # biff (2)
- # calva (33)
- # cherry (1)
- # clj-kondo (16)
- # clojure (96)
- # clojure-australia (1)
- # clojure-china (1)
- # clojure-europe (42)
- # clojure-filipino (1)
- # clojure-france (2)
- # clojure-hk (1)
- # clojure-indonesia (1)
- # clojure-japan (1)
- # clojure-korea (1)
- # clojure-my (1)
- # clojure-nl (1)
- # clojure-norway (24)
- # clojure-sg (11)
- # clojure-taiwan (1)
- # clojure-uk (1)
- # clojurescript (21)
- # cursive (22)
- # data-science (3)
- # events (7)
- # fulcro (3)
- # graalvm (4)
- # gratitude (6)
- # helix (11)
- # honeysql (7)
- # hoplon (1)
- # introduce-yourself (1)
- # jobs (2)
- # jobs-discuss (16)
- # lsp (15)
- # malli (14)
- # nbb (73)
- # practicalli (3)
- # reagent (8)
- # reitit (5)
- # releases (1)
- # ring (5)
- # rum (3)
- # sci (17)
- # scittle (7)
- # shadow-cljs (22)
- # tools-deps (26)
- # xtdb (9)
Can one call scittle functions from external js code (js file or module)?
@chromalchemy Yes, just define them on the global window. This is the first example on the scittle docs.
Ok thanks. I had tried that, but was getting “function undefined” errors.
I think the problem was I had to put the calling function behind window.onload
window.onload = function(){
test_fn('Hello from JS script tag');
}
This is working: HTML
<script src="" type="application/javascript"></script>
<script type="application/x-scittle" src="cljs/mycljs.cljs"></script>
<script type="text/javascript" src="js/myjs.js"></script>
<button onclick="test_fn('Hello from HTML Button')">
Click me!
</button>
CLJS
(ns mycljs)
(defn test-fn [s]
(js/console.log s))
;; export function to use from JavaScript:
(set! (.-test_fn js/window) test-fn)
(test-fn "Hello from Scittle file")
JS
window.onload = function(){
test_fn('Hello from JS file');
}
log
> Hello from Scittle file
> Hello from JS file
> Hello from HTML Button (on click)

It seemed to require window.onload
if the js caller fn was in another script tag, or script tag with source js file.
The scittle repo example does work as is for invocation from html-tag.