n0hoka
Last Updated: February 25, 2016
·
1.917K
· ivanbokii
Adventure time adventure time with finn and jake 31251861 1224 792

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()
Say Thanks
Respond