+ 1

If two or more addEventListeners are used to call a particular function, can I remove just the one that called it?

If 2 or more addEventListeners are used to call 1 function, can I remove just the 1 that called it? Is what calls the function passed into and usable within it? Can I track what called the function? EDIT:I guess I asked about the remove but what I'm curious about is a function that can be called by various EventListeners, is what called it passed into it - where it was called from and what exact event triggered it? This is hypothetical and I don't have an example. Solved: Thank you Gordon. Pao’s reference to that dev.to post answered what was bugging me.

7th Aug 2019, 7:37 PM
James
James - avatar
3 odpowiedzi
+ 2
1. Quick Answer Yes, demo : https://code.sololearn.com/Wrudkm9aGBH5/?ref=app 2. In-depth understanding removeEventListener is useful only when 2.1. when you are using the addEventListener function, https://code.sololearn.com/W0ehmlP2Y3I3/?ref=app 2.2. and when you use named function, otherwise you have to use a hack like this : https://www.sololearn.com/discuss/1644987/?ref=app
7th Aug 2019, 11:51 PM
Gordon
Gordon - avatar
0
why do you have two if you delete one of them anyway? 😅 can't you just have the one?
7th Aug 2019, 7:49 PM
Anton Böhler
Anton Böhler - avatar
0
perhaps post your code here, or everthing that is relevant... that would probably help😄
7th Aug 2019, 7:57 PM
Anton Böhler
Anton Böhler - avatar