Accessing “this” in Clojurescript

99封情书 提交于 2019-12-03 23:47:22

问题


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))))

回答1:


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



来源:https://stackoverflow.com/questions/15531261/accessing-this-in-clojurescript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!