Created
January 5, 2013 20:19
-
-
Save Raynos/4463430 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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