New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.stopListening can cause callbacks added via .on to be removed as well #4210
Comments
So this is effectively how
So
Perhaps there is room to improve the docs, though the |
@paulfalgout thanks for clarifying the functionality, that is kinda what I suspected was going on TBH which is why I didn't assume it was a bug. I do think some clarification in the docs would help. The part you refer to actually reads:
Which, as I understand it, refers to when you pass an object to it i.e. I think it could use some clarification where it says
The word 'registered' links to the docs for Perhaps it would be better to link to a proper definition of 'registered callback'? Something like: "a registered callback is one that is added via |
OK so I'm not sure if this is really a bug or just something that needs clarifying in the documentation... but here goes.
I have some code that uses a mixture of
.on
and.listenTo
to setup event handlers. This is because I want to use.stopListening
to remove all the event handlers added via.listenTo
whilst keeping those that I added via.on
.What I found is that if you pass
this
as the the context to.on
then calling.stopListening
will also cause the event handlers added via.on
to be removed as well - when I would expect that calling.stopListening
would remove only those event handlers added via.listenTo
(or.listenToOnce
).I have set up an example of this in codepen. The idea is that you should be able to:
.stopListening
), and thenBut what actually happens is that the call to
.stopListening
removes all the event handlers.As you can see in the commented out code, not passing
this
as the context (but instead usingFunction.bind
to set it) means works fine i.e. the call to.stopListening
then only removes event handlers added via.listenTo
.The text was updated successfully, but these errors were encountered: