28

Is there a way to access the "this" object in clojurescript?

I am having issues with event propagation when I wrap an icon with an anchor and try to attach a handlder to the anchor. Without access to "this" in the handler I am constantly dealing with the inner icon firing the event sometimes and the anchor firing other times.

edit:

As was suggested below, this-as is the way to do this. An example could be

(defn my-handler
  [e]
  (this-as this
    (let [data-attr (.data ($ this) "my-attr")]
      (log data-attr))))
Community
  • 1
  • 1
Jon Rose
  • 1,457
  • 1
  • 15
  • 25
  • 3
    Consider marking the answer as the accepted answer, instead of editing your original post. – Ryan Dec 27 '14 at 20:29

1 Answers1

35

Use ClojureScript's this-as macro: https://github.com/clojure/clojurescript/commit/09ff093dc86b455e3090ce3612c5e01f3b5bada6.

jbouwman
  • 2,067
  • 2
  • 16
  • 15
eagleflo
  • 1,184
  • 9
  • 14