Clojurescript this-as macro points to global object

Viewed 2855

During writting reactjs tutorial in clojurescrtipt i've found that this-as macro compiles to

(function(){var t = this; return t;}

which always points to window inside react classes. Sometimes i can workaround this by js* this but not inside let or map cuz they are also compiled to functions.

How can i access react js this inside let form?

Situation on fiddle: http://jsfiddle.net/VkebS/57/

and a piece of tutorial FYI:

(def comment-list 
  (React/createClass 
   #js{:render 
       (fn [] (dom/div #js {:className "commentList"}
                       (let [d (this-as t (.. t -props -data))]
                         (map #(commnt #js {:author (:author %)} (:text %)) d))))}))

PS: i can use native array for data and native map function

(def comment-list 
  (React/createClass 
   #js{:render 
       (fn [] (dom/div #js {:className "commentList"}
                       (.map (.. (js* "this") -props -data) #(commnt #js {:author (:author %)} (:text %)))))}))

that works, but...

1 Answers
Related