This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
Trying to get hold of the *file*
but it is returning nil
https://github.com/sher/nbb/blob/extend-fastify/examples/fastify/src/fnbb/plugins/statics.cljs#L1-L10
(you can check out the branch and run npm i && npm run start
to confirm the behavior)
I believe that *file*
in nbb probably works the same as babashka and JVM clojure, which is to say it's only usefully bound at compile/evaluation time, so reading it from a function won't work (unless the function call also happens as part of loading a file). <https://stackoverflow.com/a/12693068> is about JVM clojure, but I think the same thing applies (but definitely don't take my word for it, test it out) 🙂
Thank you for the help. But this is not to say that all *--*
bindings are only available during comptime, right?
@borkdude you mentioned https://github.com/babashka/nbb/discussions/218 that there is a workaround to referencing javascript this
execution context. I couldn't find in the docs, could you share a sample? (whenever you have time)
this
is always a reference to an object, but you can't use this
in nbb for technical reasons. instead of using this
you can first create the object,
(let [my-object #js {}]
...)
and then create some functions:
(let [my-function (fn [] (do-something-with-object my-object))]
...
and then attach that function to the object:
(aset my-object "foo" my-function)
Oh I see, the same thing I found here in https://github.com/babashka/sci#this-as. So there is no way to reference this
within a function execution that is provided by an external library.