Skip to content

Instantly share code, notes, and snippets.

@Raynos
Created January 5, 2013 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Raynos/4463430 to your computer and use it in GitHub Desktop.
Save Raynos/4463430 to your computer and use it in GitHub Desktop.
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