-
-
Save paulogaspar7/1761640 to your computer and use it in GitHub Desktop.
Use Backbone.js classes as native CoffeeScript classes
This file contains hidden or 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 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