n0hoka
Last Updated: February 25, 2016
·
2.001K
· ivanbokii

Coffeescript classes and Backbone.js

You can use Coffeescript classes for Backbone's Models, Views, Collections and Routers:

instead of:

MyView = Backbone.View.extend
    events:
        'click .test-button': 'someAction'

you can do this:

class MyView extends Backbone.View
    events:
        'click .test-button': 'someAction'

The cool thing about it is that you can use class methods directly, instead of specifying it as one of the parameters of Backbone's extend method call:

class MyView extends Backbone.View
    @imClassMethod: ->

and call it by

MyView.imClassMethod()