Create custom named events in Backbone.js
In Backbone, Events is a module that can be mixed in to any object, giving the object the ability to bind and trigger custom named events. Events do not have to be declared before they are bound, and may take passed arguments. For example:
1 2 3 4 5 6 7 8 9 10 11 |
<script> var person = {}; _.extend(person, Backbone.Events); person.on("scream", function(msg) { alert("I am " + msg); }); person.trigger("scream", "screaming"); </script> |
Leave a Comment