Created
January 26, 2014 23:00
-
-
Save brian-mann/8640612 to your computer and use it in GitHub Desktop.
Coffeescript classes vs Javascript extend
This file contains hidden or 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
| // All Backbone objects have the extend method built in. | |
| // This serves the same primary purpose as Coffeescript's extends keyword. | |
| // After all, they were actually written by the same person: Jeremey Ashkenas | |
| // Coffeescript Implementation for Backbone Model | |
| class Entities.User extends Backbone.Model | |
| defaults: | |
| firstName: "Brian" | |
| initialize: -> | |
| console.log @get("firstName") | |
| // Javscript Implementation for Backbone Model | |
| Entities.User = Backbone.Model.extend({ | |
| defaults: { | |
| firstName: "Brian" | |
| }, | |
| initialize: function(){ | |
| console.log(this.get("firstName")); | |
| } | |
| }) | |
| // Coffeescript Implementation for Marionette Views | |
| class List.User extends Marionette.ItemView | |
| template: "path/to/template" | |
| tagName: "li" | |
| onRender: -> | |
| @$el.addClass "active" | |
| class List.Users extends Marionette.CollectionView | |
| tagName: "ul" | |
| itemView: List.User | |
| // Javascript Implementation for Marionette Views | |
| List.User = Marionette.ItemView.extend({ | |
| template: "path/to/template", | |
| tagName: "li", | |
| onRender: function(){ | |
| this.$el.addClass("active") | |
| } | |
| }) | |
| List.Users = Marionette.CollectionView.extend({ | |
| tagName: "ul", | |
| itemView: List.User | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment