fancy
fancy

Reputation: 51393

Is there any way to automatically output all backbone.js triggers/events in the console?

Is there any way to automatically output all backbone.js triggers/events in the console so I can see everything that is going on?

Thanks!

Upvotes: 4

Views: 1871

Answers (1)

Derick Bailey
Derick Bailey

Reputation: 72868

To do this, you would need to override the Backbone.Events 'trigger' method, and then call the code you want before calling back to the original method.

something like this should work:

var originalTrigger = Backbone.Events.trigger;
Backbone.Events.trigger = function(){
  console.log("Event Triggered:");
  console.log(arguments.join(", "));
  originalTrigger.apply(this, arguments);
}

i'm not sure off-hand, but you may need to slice the arguments into an actual array to call apply:

originalTrigger.apply(this, Array.prototype.slice.call(arguments));

Upvotes: 5

Related Questions