Fork me on GitHub
#clojurescript
<
2022-11-29
>
dang duomg 19101:11:40

is there a way to inspect the javascript output of a clojurescript source code

p-himik05:11:36

You mean, for a particular piece of code? Or the whole build of a project?

dang duomg 19106:11:16

for a piece of code

p-himik06:11:11

ClojureScript 1.11.60
cljs.user=> (set! *print-fn-bodies* true)
true
cljs.user=> (fn [] (+ 1 2))
#object[ret__7815__auto__ "function (){
return ((1) + (2));
}"]
cljs.user=>

thheller07:11:30

there is a "Generated JS" tab on the right

dang duomg 19108:11:35

why does this happen

p-himik08:11:36

cljs.user=> (doc deftype)
-------------------------
cljs.core/deftype
([t fields & impls])
Macro
  (deftype name [fields*]  options* specs*)

  Currently there are no options.

  Each spec consists of a protocol or interface name followed by zero
  or more method bodies:

  protocol-or-Object
  (methodName [args*] body)*
[...]
You're missing a protocol or an interface there.

Ferdinand Beyer08:11:41

…or Object, which is neither a protocol nor an instance. You will also need to change your full-name to accept a this first argument. However, maybe you should rethink what you are trying to do, looks like you are trying to apply OOP in Clojure. You might be better off using a plain defn for your full-name method.

dang duomg 19108:11:47

it says full-name is undefined

Ferdinand Beyer08:11:47

When extending a protocol, use the function that the protocol defined, not the method syntax. So (full-name person) instead of (.full-name person)

Ferdinand Beyer08:11:11

Think of it like this: defprotocol defines “global” functions (in its namespace), and a way of extending the protocol by providing implementations for these functions. So after defprotocol, full-name is a normal function. deftype then just “hooks into” the protocol, it does not actually define methods when extending a protocol. To actually provide methods, extend Object:

(defprotocol Person [first-name last-name]
  Object
  (full-name [_this]
    (str first-name last-name)))