Question

The official and supported syntaxes to access clojurescript properties are described in http://dev.clojure.org/jira/browse/CLJS-89. For instance:

(.-myprop obj)

However, I've seen some code use this...

(defn get1 [my]
   my.e.target.value)

...which also compiles successfully to plain & simple property access. Just like the "official" version would:

(defn get2 [my]
   (.. my -e -target -value))

Can/Should I use it? (I do like the former syntax better)

One disadvantage I could think of is that the semantics are different and code analysis tools might not work.

Was it helpful?

Solution 2

Via:

js/console.log in ClojureScript

David Nolen's comment says that it will stay and is supported so it is safe to use.

OTHER TIPS

You should use the dot operator and variants to access Js interop because it is the idiomatic way and also it allows you differentiate between property access and function calls which you don't with the /.

That syntax is there to access namespaced values, (like js/Array, closure.string/split, sample.until/inspect) and it shouldn't be used for interop purposes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top