Suppose I want to create, using ghcjs-dom, an event listener which responds to a click, and then removes itself.(假设我想使用ghcjs-dom创建一个事件侦听器,该事件侦听器对单击做出响应,然后将其自身删除。)
I have(我有)
addListener :: (IsEventTarget t, IsEvent e)
=> t -> EventName t e -> SaferEventListener t e -> Bool -> IO ()
removeListener :: (IsEventTarget t, IsEvent e)
=> t -> EventName t e -> SaferEventListener t e -> Bool -> IO ()
to add and remove, and(添加和删??除,以及)
newListener :: (IsEvent e) => EventM t e () -> IO (SaferEventListener t e)
to construct the listener out of an EventM
.(从EventM
构造侦听EventM
。) How can I access the SaferEventListener
(which I will only later construct) from within the EventM
, in order to remove it when the event occurs?(我怎样才能访问SaferEventListener
从(我将只是后来建造)的内EventM
,以便在事件发生时将其删除?)
In JavaScript, you use a named function expression as your callback to addEventListener
, and then apply removeEventListener
to that name from within the callback.(在JavaScript中,您可以使用命名函数表达式作为addEventListener
的回调,然后在回调中将removeEventListener
应用于该名称。) But nothing analogus seems to be possible here.(但是,这里似乎没有任何类比。) Or am I missing something?(还是我错过了什么?)
ask by Graham Leach-Krouse translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…