_.extend(object, Backbone.Events);
object.on("myalert:one", function(msg) {
document.body.innerHTML+=("eve1 " + ' msg:= '+msg+ ' ;name:= '+this.name);
},context);
object.on("myalert:two", function(msg) {
document.body.innerHTML+=(" eve2 " + ' msg:= '+msg+ ' ;name:= '+this.name);
});
I want сall all events are tied to this object with mask alert:.
object.trigger("myalert", "param");
There isn't any namespacing in
Backbone.Events
but you could add your own. For example, something like this:would allow you to say
obj.trigger_matching(/^myalert:/, 1, 2, 3)
and The Right Thing would happen.Demo: http://jsfiddle.net/ambiguous/p8p5R/
That will trigger multiple
'all'
events (one for eachthis.trigger.apply
) which may or may not be what you want. If it isn't then replace thethis.trigger.apply
call with a custom version of the standardtrigger
so that you can trigger at most one'all'
event.