I read an article (link) which explains that the seconde argument of addEventListener
can be a function or an object implementing handleEvent
method.
In the But wait there’s more section of this article, it says using handleEvent
can avoid removing and re-attach the event handler. But I'm wondering if this is a better way than repeatedly 'add' and 'remove'? In terms of tidy code, performance or whatever?
Thank you all!
Using an object as a listener:
has the following advantages:
this
from the Event objectReferences
An alternative way to addEventListener - Ajaxian
Document Object Model (DOM) Level 3 Events Specification: Interface EventListener
W3C DOM Level 2 version 1.0 - Java API: Interface EventListener
Web IDL: Callback Interfaces
WebIDL-1: Implementation Report - All Results