Created
March 19, 2014 14:31
-
-
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__.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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