Last active
August 29, 2015 13:55
-
-
Save scottcorgan/8713870 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 bind = function (selector, event) { | |
return binder(selector, event); | |
}; | |
var binder = function (selector, event) { | |
var listeners = []; | |
document.querySelector(selector) | |
.addEventListener(event, function (e) { | |
listeners.forEach(function (listener) { | |
listener.call(this, e) | |
}; | |
}); | |
function addListener () { | |
listeners.push(listener); | |
}; | |
addListener.selector = selector; | |
addListener.event = event; | |
return addListener; | |
}; |
This file contains hidden or 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
// This is basically the same idea behind | |
// using promises for events, except | |
// the binding is partially applied so that | |
// we can send any amount of callbacks to | |
// the event listener. | |
var clicked = bind('.element', 'click'); | |
clicked(function (e) { | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment