Why would you want to bind event handlers using “listenTo()” instead of “on()”?


Please explain why do you think this question should be reported?

Report Cancel

There are two advantages to using “listenTo()” instead of using “on()”. Typically, the way they are used is a bit different:listener.listenTo(object, event, callback) object.on(event, callback)
With “listenTo()”, the object whose events you want to listen to is passed as the first argument. In the case of “on()”, it is actually a method on that object.

The 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 needed.
The callback’s context is always set to the listener itself.

Please follow and like us:

About the Author