访问“this”在Clojurescript中 [英] Accessing "this" in Clojurescript
问题描述
有没有办法在clojurescript中访问this对象?
Is there a way to access the "this" object in clojurescript?
我是在我包装图标时有事件传播的问题使用锚并尝试将手柄连接到锚。如果在处理程序中无法访问this,我会不时处理触发事件的内部图标,并且其他时间会触发锚点。
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.
编辑:
如下所示,这就是这样做的方法。一个例子可能是
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))))
推荐答案
使用ClojureScript的 this-as
宏: https://github.com/clojure/clojurescript/commit/09ff093dc86b455e3090ce3612c5e01f3b5bada6 。
Use ClojureScript's this-as
macro: https://github.com/clojure/clojurescript/commit/09ff093dc86b455e3090ce3612c5e01f3b5bada6.
这篇关于访问“this”在Clojurescript中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!