Isso permitirá que você use mixins em seus modelos de Backbone, visualizações, coleções e roteadores.
include = (mixins...) ->
throw new Error('include(mixins...) requires at least one mixin') unless mixins and mixins.length > 0
for mixin in mixins
for key, value of mixin
@::[key] = value unless key is 'included'
mixin.included?.apply(this)
this
Backbone.Model.include = Backbone.Collection.include = include
Backbone.View.include = Backbone.Router.include = include
Então você pode fazer:
Foo =
# Executes when included
included: ->
@message = 'Hello World!'
# This method will be mixed in
bar: -> console.log @message
class MyView extends Backbone.View
@include Foo
view = new MyView
view.bar() # prints 'Hello World!