Check out this little bit of code:

(doseq [hid ["a" "b" "c"]]
  (goog.dom.appendChild (goog.dom.$ "some-element-id")
(goog.dom.createDom "div" (.strobj {"id" hid})  (str "Test-"hid)))
  (goog.events.listen (goog.dom.$ hid) goog.events.EventType.CLICK,
(fn [e] (js/alert hid))))

What I want it do to is add in a few div's that when clicked on simply
alert with the value their id value.  That doesn't actually happen,
what happens is that they all alert with the "c" ie. the last value in
the list.  This code, on the other-hand works:

(defn hidfn [hid]
  (fn [e] (js/alert hid))
  )
(doseq [hid ["a" "b" "c"]]
  (goog.dom.appendChild (goog.dom.$ "the-receptor")
(goog.dom.createDom "div" (.strobj {"id" hid})  (str "Test-"hid)))
  (goog.events.listen (goog.dom.$ hid) goog.events.EventType.CLICK,
(hidfn hid)))

Shouldn't the clojurescript compiler detect that the usage of "hid" in
the function in the first case requires the creation of an anonymous
function to close around that value?  Why do I have to do it manually?

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to