Created
August 29, 2014 23:00
-
-
Save darbicus/46d72aed17f93d61b4d6 to your computer and use it in GitHub Desktop.
Sometimes I wish addEventListener in javascript would return an object so that you can cancel the event without having to name the function. So I created one but instead of replacing the prototype function I just added a new function addEvent which takes the same arguments as the addEventListener function and it returns a function that removes t…
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
EventTarget.prototype.addEvent = function () { | |
var args = [].slice.call(arguments); | |
var remove = (function () { | |
this.removeEventListener.apply(this, args); | |
}).bind(this); | |
this.addEventListener.apply(this, arguments); | |
return remove; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment