This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-11-29
Channels
- # adventofcode (9)
- # announcements (2)
- # aws (78)
- # babashka (55)
- # beginners (97)
- # biff (9)
- # calva (11)
- # cherry (2)
- # cider (8)
- # clerk (7)
- # clj-kondo (6)
- # clj-on-windows (4)
- # clojure (213)
- # clojure-austin (6)
- # clojure-europe (63)
- # clojure-nl (1)
- # clojure-norway (5)
- # clojure-spec (10)
- # clojure-uk (1)
- # clojurescript (14)
- # clr (2)
- # community-development (3)
- # conjure (14)
- # datomic (2)
- # deps-new (5)
- # dev-tooling (10)
- # editors (3)
- # emacs (3)
- # etaoin (19)
- # events (4)
- # fulcro (71)
- # holy-lambda (20)
- # java (3)
- # jobs (2)
- # leiningen (4)
- # lsp (24)
- # malli (15)
- # membrane (107)
- # music (1)
- # off-topic (29)
- # pedestal (4)
- # polylith (1)
- # portal (2)
- # rdf (5)
- # releases (7)
- # scittle (5)
- # shadow-cljs (8)
- # tools-build (15)
- # tools-deps (6)
- # xtdb (13)
is there a way to inspect the javascript output of a clojurescript source code
for a piece of code
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=>
why does this happen
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.…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.
it says full-name is undefined
When extending a protocol, use the function that the protocol defined, not the method syntax. So (full-name person)
instead of (.full-name person)
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)))
all good