Skip to content

Instantly share code, notes, and snippets.

@murindwaz
Forked from thurloat/ModularView.coffee
Created February 5, 2013 18:03
Show Gist options
  • Save murindwaz/4716343 to your computer and use it in GitHub Desktop.
Save murindwaz/4716343 to your computer and use it in GitHub Desktop.
# All of your views should inherit from the BaseView. As a result you get the
# globalEvents functionality for free. The globalEvents hash is similar to that
# of the built-in Backbone events hash. It automatically binds event names to
# instance methods.
#
# class TestView extends ModularView
#
# globalEvents:
# "PhoneRang": "answerPhone"
#
# answerPhone: ->
# # phone answering logic
#
# Also note that the correct value of `this` is passed in.
#
class ModularView extends Backbone.View
delegateEvents: (events) ->
super
@globalEvents = @globalEvents or {}
for event, handler of @globalEvents
@options.pubSub.bind event, _.bind @[handler], @
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment