Skip to content

Instantly share code, notes, and snippets.

@paulogaspar7
Forked from mattmccray/backbone_helper.coffee
Created February 7, 2012 20:05
Show Gist options
  • Save paulogaspar7/1761640 to your computer and use it in GitHub Desktop.
Save paulogaspar7/1761640 to your computer and use it in GitHub Desktop.
Use Backbone.js classes as native CoffeeScript classes
# Backbone CoffeeScript Helpers by M@ McCray.
# Source: http://gist.github.com/625893
#
# Use Backbone classes as native CoffeeScript classes:
#
# class TaskController extends Events
#
# class TaskView extends View
# tagName: 'li'
# @SRC: '<div class="icon">!</div><div class="name"><%= name %></div>'
#
# constructor: ->
# super
# @template= _.template(TaskView.SRC)
# @render() if @model?
#
# render: ->
# $(@el).html @template( @model.toJSON() )
#
# Etc...
#
class Events
_.extend(Events::, Backbone.Events)
this.Events = Events
class Model
constructor: ->
Backbone.Model.apply(this, arguments)
_.extend(Model::, Backbone.Model.prototype)
this.Model = Model
class Collection
constructor: ->
Backbone.Collection.apply(this, arguments)
_.extend(Collection::, Backbone.Collection.prototype)
this.Collection = Collection
class View
constructor: ->
Backbone.View.apply(this, arguments)
_.extend(View::, Backbone.View.prototype)
this.View = View
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment