jashkenas / backbone

Give your JS App some Backbone with Models, Views, Collections, and Events
http://backbonejs.org
MIT License
28.09k stars 5.39k forks source link

Listenee fails to cleanup if no listeners defined #4220

Closed pierlon closed 5 years ago

pierlon commented 5 years ago

If a listenee's listeners are not defined, it is unable to delete the listener from the listenee:

https://github.com/jashkenas/backbone/blob/5de45fc9e1cbe5f61cf459067207bbe73451ac91/backbone.js#L377

Checking for the obj._listeners object before deleting should fix this. Happy to send a PR if needed :smile: .

jashkenas commented 5 years ago

Why wouldn't they be defined?

Do you have a minimal test case that can reproduce the problem?

pierlon commented 5 years ago

I've managed to solve the issue. The _listeners object was on the Collection object. As stated in the change log:

listenTo uses the listened object's public on method

For context, I am fixing the issue of updating WordPress to v1.4.0.