Fork me on GitHub
#clojurescript
<
2021-02-25
>
tomrbowden06:02:27

Is it possible to use the JavaScript operators typeof or delete via interop with CLJS?

p-himik06:02:39

Not via interop. But you can use js-delete and goog/typeOf.

👍 3
borkdude19:02:26

Is there a way to make this work in CLJS?

cljs.user=> (let [x IDeref] (satisfies? x (atom 0)))
false

lilactown20:02:07

reading the source of the satisfies? macro, it looks like it relies on using the analyzer to get the name of the protocol so that it knows what attribute to look up on the object being checked

lilactown20:02:36

in order to change this, I think you would have to emit the name of the protocol in code somewhere where you could read it at runtime

borkdude21:02:00

yeah, I worked around this by using cond = on the protocol object and then hardcoding the satisfies...

lilactown21:02:13

I think that's your best bet

lilactown21:02:04

emitting the name in code and trying to use it at runtime, would break advanced optimizations where the attribute on the object gets renamed. emitting the check via a macro ensures that the check stays coherent after optimization

lilactown21:02:58

we could tell GCC not to optimize protocols but I don't think we want that 🙂

Noah Bogart20:02:08

whoops, wrong channel. 😬