Add a way of clearing the event listeners array and remove by ID
See original GitHub issueFeature request
- Add a method to remove every event listener on the timer (eg.
myTimer.clearEventListeners()
) removeEventListener
works by usingindexOf()
with a function, which can be unusable if using generated arrow functions. This could be solved by allowing an optionalid
to be passed along onaddEventListener
, which can later be used to identify the listener to be removed (eg.myTimer.removeEventListenerByID('secondsUpdated', 'myListener1')
). If two listeners are added with the same id, the second should override the first
Looking at the code changes needed for this it don’t look like they should be too big. I may have some time to submit a PR if you need contribution
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
How to remove all event listeners of a DOM object?
Another way to remove the event (which will also remove all the events) is to remove the node and create a new one,...
Read more >EventTarget.removeEventListener() - Web APIs | MDN
The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.
Read more >JavaScript removeEventListener() method with examples
The Javascript removeEventListener() is an inbuilt function that is used to remove removes an event handler that was previously added using ...
Read more >Remove an Event Handler - JavaScript Tutorial
This tutorial shows you how to use the removeEventListener() method to remove an event handler from an event of an element.
Read more >Removing event listeners through an identifier #208 - GitHub
An alternative to overloading obj.removeEventListener() would be adding something like obj.removeEventListenerClass("clicker") , but that seems ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Awesome, glad to be of help, thank you for the awesome library!
Hi!
I have just published the version 4.5.0 with your removeAllEventListeners method.
Thanks a lot for your contribution 😃.