Skip to content

Instantly share code, notes, and snippets.

@hshoff
Created March 8, 2012 18:50
Show Gist options
  • Save hshoff/2002656 to your computer and use it in GitHub Desktop.
Save hshoff/2002656 to your computer and use it in GitHub Desktop.
Neat Backbone.View initialization
class Component extends Backbone.View
initialize: ->
for func, args of @options
if @[func]?
if _.isArray(args)
@[func].apply?(@, args)
else
@[func].call?(@, args)
return null
class: (klass) =>
return @ unless klass?
@$el.addClass(klass)
@
# Then you can do this
component = new Component
'class': 'new-component admin'
# component.el = <div class='new-component admin'></div>
# for the compiled JavaScript:
http://bit.ly/wTap7Y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment