I'm creating an events object using a bit of backbone and underscore as follows:
var appEvents = _.extend({}, Backbone.Events);
I'm then trying to create a function that will console.log all and any event triggered to this object, regardless of where, how or what listeners it has, but am kinda unsure how I'd do that. I'm still experimenting with Backbone.
I think using the listenTo method is the way to go... but again, not sure how I'd implement that.
Backbone. js trigger Event is used to invoke or callback the function for the given event or a space-delimited list of events. The subsequent arguments will be passed along to the event callbacks in order to trigger it.
Backbone. js is a model view controller (MVC) Web application framework that provides structure to JavaScript-heavy applications. This is done by supplying models with custom events and key-value binding, views using declarative event handling and collections with a rich application programming interface (API).
BackboneJS is a lightweight JavaScript library that allows to develop and structure the client side applications that run in a web browser. It offers MVC framework which abstracts data into models, DOM into views and bind these two using events.
You can just use Backbone's special all
event:
appEvents.on("all", function(eventName){
console.log(eventName + ' was triggered!');
});
var object = {};
_.extend(object, Backbone.Events);
object.on("alert:param1", function(msg) {
alert("Сработало " + msg);
});
object.on("alert:param2", function(msg) {
alert("Сработало " + msg);
});
object.on("all", function(eventName) {
console.log(eventName);
});
object.trigger("alert:param2", "событие");
object.trigger("alert:param1", "событие");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With