Created
February 21, 2012 07:35
-
-
Save hshoff/1874862 to your computer and use it in GitHub Desktop.
Nice way to initialize Backbone.Views
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
Backbone.Component extends Backbone.View | |
initialize: -> | |
for func, args of @options | |
unless _.isArray(args) | |
@[func]?.call(@, args) | |
else | |
@[func]?.apply(@, args) | |
render: => | |
@$parent.append(@el) | |
@ | |
show: => | |
@delegateEvents(@events) | |
@class('show') | |
@ | |
class: (klass) => | |
@$el.addClass(klass) | |
@ | |
# Then you can do this | |
component = new Backbone.Component | |
'class': "new-component admin" | |
'render': true | |
'show': true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment