Created
February 1, 2022 09:24
-
-
Save queviva/d4d56783e0849dbca791ade8a3e37c07 to your computer and use it in GitHub Desktop.
add|remove the same listener for multiple events
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
const Liz = { | |
lizzers: [ | |
[obj, 'event', e=>{...}], | |
[obj, 'event,event,...', e=>{...}], | |
[obj, 'event,event,...', e=>{...},{ passive: true }] | |
], | |
add: function(L = this.lizzers, v = 0) { | |
for (let [x, y, z, p = { passive: false }] of L) { | |
y.split(',').forEach(e => | |
x[['add', 'remove'][v] + 'EventListener'](e, z, p) | |
); | |
} | |
}, | |
remove: function() { this.add(this.lizzers, 1); } | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
declaring all listeners inside this object allows you to add|remove the same handler for multiple events on the same element
calling Liz.add() adds every listener; Liz.remove() removes them all for a quick 'en|dis-able' method