Skip to content

Instantly share code, notes, and snippets.

@brandonc
Created December 5, 2014 20:03
Show Gist options
  • Save brandonc/379ee50f7e74b5e87bad to your computer and use it in GitHub Desktop.
Save brandonc/379ee50f7e74b5e87bad to your computer and use it in GitHub Desktop.
Module pattern in Coffeescript
class MyCollection extends Backbone.Collection
classExtend(@, ModuleCollectionAsOptions)
# works
new MyCollection().toOptionsJSON()
window.classExtend = (klass, module) ->
_.extend(klass.prototype, module.prototype)
class ModuleCollectionAsOptions
toOptionsJSON: (textAttribute="title")->
@map (model) ->
value: model.id
text: model.get(textAttribute)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment