Fork me on GitHub
#clojurescript
<
2022-07-11
>
stagmoose09:07:48

What's the restriction that stop me from using #js in front of mapv

(mapv (fn [x] #js {:i (str x) :x x :y 0 :w 2 :h 2}) (range 2))
;; => [#js {:i "0", :x 0, :y 0, :w 2, :h 2} #js {:i "1", :x 1, :y 0, :w 2, :h 2}]
while:
(js/console.log #js (mapv (fn [x] #js {:i (str x) :x x :y 0 :w 2 :h 2}) (range 2)))
not working
(js/console.log (clj->js (mapv (fn [x] #js {:i (str x) :x x :y 0 :w 2 :h 2}) (range 2))))
this working Is it because #js can only apply to pure data? like #js [], #js {}

thheller09:07:46

#js is a reader literal. so it converts the datastructure following it into the respective JS equivalent

parens 1
thheller09:07:00

so it happens at read time not at runtime

thheller09:07:39

mapv returns a vector. if you want a javascript array just use (into-array (map ... (range 2))

👌 1
stagmoose09:07:44

sounds reasonable. thanks Thomas!