Created
December 5, 2014 20:03
-
-
Save brandonc/379ee50f7e74b5e87bad to your computer and use it in GitHub Desktop.
Module pattern in Coffeescript
This file contains 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
class MyCollection extends Backbone.Collection | |
classExtend(@, ModuleCollectionAsOptions) | |
# works | |
new MyCollection().toOptionsJSON() |
This file contains 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
window.classExtend = (klass, module) -> | |
_.extend(klass.prototype, module.prototype) |
This file contains 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
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