Should all Backbone on/off events be replaced with listenTo/stopListening?

backbone.js

Solution

For the most part, you understand it correctly. Here is a discussion on the matter from their github repository: https://github.com/documentcloud/backbone/issues/1923#issuecomment-11462852

`listenTo` and `stopListening` keep track of state. It will take care of cleanup for you at the cost of a little code overhead. In just about every case I can think of you'd want this behavior for your views, but you wouldn't be at fault for handling on/off calls yourself either; they won't be deprecating `on` and `off` any time soon.

Problem

As far as I have been able to tell, `listenTo` and `stopListening` should replace `on` and `off` respectively. Do I understand that correctly? Is there any situation where `on`/`off` should be used instead of `listenTo`/`stopListening`? Edit: As I went to refactor my code, it became obvious that there are some cases for `on` over `listenTo`. The documentation is pretty clear that it is for when one object listens to another object: Tell an object to listen to a particular event on an other object. Therefore, when a `collection` or `model` is listening to an event on itself, we should use `on` instead of `listenTo`. Assuming I have this correct... The simple rule to follow is this: Use `listenTo` when listening for events on another object. Use `on` when listening to events on self.

Original source

Related problems