Catch all events except in reset

2019-07-03 04:12发布

问题:

I wanna catch all events except 'reset'. I've a code like this initialized inside a View.

messagesCollection.on 'all', @_handleMessageChanges, @

Right now it works for all events. As I've mentioned above I don't need to catch in a reset event.

How can I resolve this issue? Please help us.

回答1:

When using all, the first argument is the event. So, you can do

_handleMessageChanges: function(event, ...) {
    if ( event === 'reset' ) return;
} 

See it in action here: http://jsfiddle.net/nxs9q/1

From the docs:

"all" — this special event fires for any triggered event, passing the event name as the first argument.