Created
July 11, 2019 19:57
-
-
Save jimkang/dccf629f43ee39281a8ac3150e3dcdbd to your computer and use it in GitHub Desktop.
Basic addEventListener and removeEventListener, in case I need it later
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 eventListeners = { | |
eventName: [] | |
}; | |
function addEventListener(type, listener) { | |
var listeners = eventListeners[type]; | |
if (listeners) { | |
listeners.push(listener); | |
} | |
} | |
function removeEventListener(type, listener) { | |
var listeners = eventListeners[type]; | |
if (listeners) { | |
let index = listeners.indexOf(listener); | |
if (index > -1) { | |
listeners.splice(index, 1); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment