4

I stumbled upon the official Om example under "examples/mixins", there's a definition as this:

(def MyComponent (let [obj (om/specify-state-methods! (clj->js om/pure-methods))]
    (aset obj "mixins" #js [TestMixin])
    (js/React.createClass obj)))

What does "#js" mean? I couldn't find any Clojure documentation on symbol "#" when it's used in this way.

Alex Miller
  • 69,183
  • 25
  • 122
  • 167
Minos Niu
  • 85
  • 6

3 Answers3

6

From the Om tutorial:

#js {...} and #js [...] is what is referred to as a reader literal. ClojureScript supports data literals for JavaScript via #js. #js {...} is for JavaScript objects:

#js {:foo "bar"}  ;; is equivalent to
#js {"foo" "bar"}
Diego Basch
  • 12,764
  • 2
  • 29
  • 24
6

First of all Om is a Clojurescript library. There are some differences between Clojure and Clojurescript, they are documented here.

#js is called a tagged literal, that comes from edn, basically a tagged literal tells the reader how to parse the data, in the case of #js it tells the reader to parse the data as a Javascript object. Take a look here for more information.

Rodrigo Taboada
  • 2,727
  • 4
  • 24
  • 27
0

All dispatch reader macros begin with #. When you see this it means something special will happen at the moment the code is read, and that is no different with #js than with #( or #_ or even #{ for sets. In this case it tells the reader that what follows is a JavaScript literal.

More here: http://clojure.org/reader#The%20Reader--Macro%20characters

johnbakers
  • 24,158
  • 24
  • 130
  • 258