Google News
logo
Backbone - Interview Questions
What are the main advantages of using "listenTo()" to bind event handlers instead of "on()"?
There are mainly two advantages to using "listenTo()" instead of using "on()" to bind event handlers. See the syntax of using these both because they are used differently :
 
Syntax :
 
listener.listenTo(object, event, callback)  
object.on(event, callback)  
 
While using "listenTo()", the object whose events you want to listen to is passed as the first argument. On the other hand, in the case of "on()", it is a method on that object.
 
The key advantages of "listenTo()" over "on()" are :
 
* The listener keeps track of all the event handlers, making it easier to remove them all at once when required.
* The callback's context is always set to the listener itself.
Advertisement