I have a property called "user-agent" in a javascript object that I would like to get. How to do it in clojurescript?
(js/eval "a = {'user-agent': 'curl/7.22.0'}") (js/eval "a['user-agent']") ;=> curl/7.22.0 (.-user-agent js/a) ;=> (returns nothing) (. js/a -user-agent) ;=> (returns nothing)
Is it because properties are extracted using dot notation instead of brackets here? https://github.com/clojure/clojurescript/blob/master/src/clj/cljs/compiler.clj#L734
Use aget:
aget
(aget js/a "user-agent")
, clojurescript , ? ! . , munging , , (.-user-agent js/a), - a.user_agent.
?
!
(.-user-agent js/a)
a.user_agent
clojurescript, munging , , javascript interop. , aget aset.
aset