macro | since v0.0-927 | imported clojure.core/.. | Edit |
(.. x form)
(.. x form & more)
For interop, the ..
macro allows method/property chaining on the given JavaScript object o
.
It essentially combines the thread-first ->
macro with the .
operator.
// JavaScript
"a b c d".toUpperCase().replace("A", "X")
//=> "X B C D"
;; ClojureScript
(.. "a b c d"
toUpperCase
(replace "A" "X"))
;;=> "X B C D"
This is expanded to:
(. (. "a b c d" toUpperCase) (replace "A" "X"))
which is equivalent to:
(.replace (.toUpperCase "a b c d") "A" "X")
;;=> "X B C D"
Compare to the equivalent form using the thread-first ->
macro:
(-> "a b c d"
.toUpperCase
(.replace "A" "X"))
;;=> "X B C D"
form => fieldName-symbol or (instanceMethodName-symbol args*) Expands into a member access (.) of the first member on the first argument, followed by the next member on the result, etc. For instance: (.. System (getProperties) (get "os.name")) expands to: (. (. System (getProperties)) (get "os.name")) but is easier to write, read, and understand.
(defmacro ..
{:added "1.0"}
([x form] `(. ~x ~form))
([x form & more] `(.. (. ~x ~form) ~@more)))