Skip to content

Instantly share code, notes, and snippets.

@Raynos Raynos/on.js
Created Jan 5, 2013

Embed
What would you like to do?
var stop = eventTarget.on("event", function optionalFilter(event) {
return event.target.classList.contains("some-class")
}, function listener(event) {
// handle event
})
// stop listening()
stop()
// sugar
function matchesSelector(selector) {
return function (event) {
return event.target.matchesSelector(selector)
}
}
eventTarget.on("event", matchesSelector(".some-class"), listener)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.