When I try to bind a router event in the initialize method, I encounter some unexpected behavior:
var View = Backbone.View.extend({
initialize: function() {
router.on("route:test", this.update);
},
update: function() {
console.log('This works');
}
});
However, when I attempt the following approach, it does not seem to work as expected:
var View = Backbone.View.extend({
events: {
"route:test": "update"
},
initialize: function() { },
update: function() {
console.log('This never gets called');
}
});
I am unsure if I have made an error in the second case or if there is a misunderstanding on my part.
Can someone clarify whether the events
property within a view is only intended for DOM-level events?