Skip to content

Instantly share code, notes, and snippets.

@mataspetrikas
Created February 23, 2011 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mataspetrikas/840452 to your computer and use it in GitHub Desktop.
Save mataspetrikas/840452 to your computer and use it in GitHub Desktop.
Backbone.View event inheritance problem
var SuperView = Backbone.View.extend({
events: {
"click a.foo": "onFooClick"
},
onFooClick: function(event) {
alert('onFooClick!');
}
});
var SubView = SuperView.extend({
events: {
"click a.bar": "onBarClick"
},
onBlackButton: function(event) {
alert('onBarClick!');
}
});
@ggarber
Copy link

ggarber commented Apr 4, 2011

I can propose you two solutions (one of them requiring changes in backbone). I commented it in my blog: http://kalimotxocoding.blogspot.com/2011/03/playing-with-backbonejs-views.html

@rxgx
Copy link

rxgx commented May 2, 2011

@ggarber I thought the point of Backbone was to prevent a long prototype-based inheritance chain. Any properties in the the child prototype object wil be used instead of the parent's.

Extending a view is good way of setting inheritance but I think you'll need an extra function that will mixin the properties of the event object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment