Skip to content

Instantly share code, notes, and snippets.

@AndersDJohnson
Last active June 5, 2019 13:36
Show Gist options
  • Save AndersDJohnson/789a4d874feb4eb1a1839bd4d4748051 to your computer and use it in GitHub Desktop.
Save AndersDJohnson/789a4d874feb4eb1a1839bd4d4748051 to your computer and use it in GitHub Desktop.
Backbone extend events view
/**
* http://danhough.com/blog/backbone-view-inheritance/
* @param child
* @return {*}
*/
ExtendEventsView.extend = function (child) {
var view = Backbone.View.extend.apply(this, arguments);
var protoEvents = this.prototype.events;
if (_.isFunction(protoEvents)) {
protoEvents = protoEvents();
}
var childEvents = child.events;
if (_.isFunction(childEvents)) {
childEvents = childEvents();
}
view.prototype.events = _.extend({}, protoEvents, childEvents);
return view;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment