19

I am working with Om and I didn't fully understand the following expression :

 (.. e -target -checked)

Here, "e" is a javascript event, and "-target -checked" is a way to access properties, if I understood well. But what about the two dots at the beginning ?

myguidingstar
  • 673
  • 4
  • 10
ThomasC__
  • 311
  • 3
  • 9

1 Answers1

41

That's one of the forms for clojurescript interop.

The most basic one is

(.method object) ; Equivalent to object.method()
(.-property object) ; Equivalent to object[property]

In order to access several nested properties, there is a shortcut with the .. operator, so that you can do:

(.. object -property -property method)
(.. object -property -property -property)

Instead of:

(.method (.-property (.-property object)))
(.-property (.-property (.-property object)))

And the code results in a cleaner more readable expression. As you can see, the parallel is that the form is the same as normal interop but without the dot, so that property access turns into -prop and method calls turn into method (no dot).

Those forms above are equivalent to this JS forms:

object[property][property][method]()
object[property][property][property]

Read up this good post to learn more about clojurescript's javascript interop forms: http://www.spacjer.com/blog/2014/09/12/clojurescript-javascript-interop/

Joaquin
  • 2,714
  • 20
  • 19
  • From the link @joaquin shared, you can also use the form: `(aget js/object "prop1" "prop2" "prop3")` – pdoherty926 Nov 25 '14 at 18:25
  • I think you mean `object["property"]` instead of `object[property]` (i.e., the former includes quotes). – George Mar 04 '16 at 08:35