Web Components
handleEvent()
Event handlers in javascript can take a handler function callback, or an object. If the object has a handleEvent()
method, that will be called when any event fires. Debinding events works the same, pass this
to .removeEventListener('some-event', this)
function someContext () {
return {
handleEvent() {
// this will respond do any event triggered on the element
}
}
}
el.addEventListener('some-event', this)
This can lead to much simpler component markup, especially when debinding events1