The Backbone 0.9.0 changelog says:
A view's events hash may now also contain direct function values as well as the string names of existing view methods.
When I try the following it fails, saying that the value for the event is undefined
.
var BB = Backbone.View.extend({
'initialize': function() {
this.$el.html('<input type="button" value="Click me!" />');
jQuery('body').html(this.el);
},
'events': {
'click input[type="button"]': this.buttonClicked
},
'buttonClicked': function() {
alert('button clicked!');
}
});
window.b = new BB()
Am I misunderstanding the new feature? Can somebody explain how it works differently than I expected? Perhaps it's just my JavaScript syntax/value of 'this' at definition time that is borked.
The way I'm used to doing it still works:
'events': {
'click input[type="button"]': 'buttonClicked'
},