Skip to content

Instantly share code, notes, and snippets.

@brian-mann
Created January 26, 2014 23:00
Show Gist options
  • Select an option

  • Save brian-mann/8640612 to your computer and use it in GitHub Desktop.

Select an option

Save brian-mann/8640612 to your computer and use it in GitHub Desktop.
Coffeescript classes vs Javascript extend
// 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