scittle

2023-07-15T14:38:05.990469Z

I found this error while interop-ing with scittle, I did found some workarounds, but why is this?

<script>
    var a_value = "hello a_value"
    var another = { value: "hello_another_value"}
</script>
<script type="application/x-scittle">
    (println js/a_value)
    (println js/another.value)
    ;; (set! js/a_value "goodbye a_value") ;; this is an error "Invalid assignment target"
    ;; (set! js/another.value "goodbye another_value") ;; this is also the same error
    (set! (. js/window -a_value) "goodbye a_value")
    (println js/a_value)
    (set! (.. js/another -value) "goodbye another_value")
    (println js/another.value)
    (set! (.-value js/another) "goodbye another_value 2")
    (println js/another.value)
</script>

borkdude 2023-07-15T14:49:59.881219Z

@kyogatama officially you have to write (set! (.-a_value js/document) ...)

borkdude 2023-07-15T14:50:55.588269Z

$ nbb
Welcome to nbb v1.2.173!
user=> (set! (.-a_value js/globalThis) 3)
nil
user=> js/globalThis.a_value
3

2023-07-15T14:55:32.281099Z

I see, I was not expecting the error since it works in clojurescript. But I only use it in one line in my code so this is no big deal then

borkdude 2023-07-15T14:56:59.560109Z

the official syntax is what I just stated, the other one just happens to work because of the code that gets emitted, by luck stick to the official syntax and it will work in both targets

2023-07-15T14:59:29.550969Z

Will do! so that's why it's hard to find documentation on these js/some.thing when I was trying clojurescript for the first time