根据我的实验,这引用了event.currentTarget对象.
这种行为是否在标准的某处提到过?
根据“JavaScript The Definitive Guide”一书,这指的是似乎错误的事件目标. event.currentTarget似乎更合乎逻辑,因为事件处理程序被调用为HTML元素对象的方法.
有人可以澄清一下吗?
In case of bubbling I see “this” changes and means the
event.currentTarget.
解决方法
我在HTML5 event handler processing algorithm中找到了一个参考:
Invoke
callback
with one argument,the value of which is the Event objectE
,with the callback this value set toE
‘scurrentTarget
.
DOM 3级事件规范在以前的版本中没有说太多 – 它本来是语言无关的. Appendix F: ECMAScript Language Binding刚才说明了
EventListener function:
This function has no return value. The parameter shall be an object that implements theEvent
interface.
但是,当前版本省略了这些绑定.在其词汇表附录event listeners中描述:
event handler,event listener: An object that implements the
EventListener
interface and provides anEventListener.handleEvent()
callback method. Event handlers are language-specific. Event handlers are invoked in the context of a particular object (the 07003) and are provided with theevent
object itself.
此外,即将推出的DOM Level 4草案,其goals包含将DOM与EcmaScript的需求对齐,确实明确说明了in the Dispatching Events section:
If
listener
‘s callback is a Function object,its 07006 is theevent
‘s 07007 attribute value.