In Backbone, I'm using the new Backbone.listenTo
event. One of my instances has the listener attached to three different events e.g.:
this.listenTo(this._Collection, 'reset add change', this._setCollection);
It is called appropriately when it's supposed to and there are no issues there. What I don't know is how to find out which event was triggered. I have access to the e
argument using:
_setCollection: function(e) {
// Do fun stuff
}
The problem is that the e
argument only sends a copy of the collection and doesn't mention what event is actually triggered. I've tried e.type
and e.target
but those objects don't exist. Here's a copy of the e
object from Chrome Dev tools:
_byCid: Object
_byId: Object
_events: Object
add: Array[1]
change: Array[1]
remove: Array[1]
reset: Array[1]
__proto__: Object
_listenerId: "l16"
length: 3
models: Array[3]
How can I find what event was triggered?
EDIT: Answer Clarification: Although the marked answer is technically correct, as pointed out by mu_is_too_short the correct answer is using multiple handlers and not performing this type of "chicanery"