Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clojurescript : two dots in expression

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 ?

like image 299
ThomasC__ Avatar asked Nov 20 '14 23:11

ThomasC__


1 Answers

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/

like image 100
Joaquin Avatar answered Jan 03 '23 06:01

Joaquin