Skip to content

Instantly share code, notes, and snippets.

@brianmcallister
Created March 19, 2014 14:31
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 brianmcallister/9642828 to your computer and use it in GitHub Desktop.
Save brianmcallister/9642828 to your computer and use it in GitHub Desktop.
Backbone base class to inherit events all the way up the prototype chain. Obviously this only works when using CoffeeScript classes due to the use of __super__.
class BaseView extends Backbone.View
# Public: Events.
events: {}
# Public: Constructor.
#
# Returns this.
constructor: ->
# Inherit events.
cls = this
while cls.constructor.__super__
@events = _.extend _.result(this, 'events'),
_.result cls.constructor.__super__, 'events'
cls = cls.constructor.__super__
return super
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment