Skip to content

Instantly share code, notes, and snippets.

@ericallam
Created February 8, 2012 14:09
Show Gist options
  • Select an option

  • Save ericallam/1769792 to your computer and use it in GitHub Desktop.

Select an option

Save ericallam/1769792 to your computer and use it in GitHub Desktop.
Comparing js and coffeescript
(function() {
var TodosView,
__hasProp = Object.prototype.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
TodosView = (function(_super) {
__extends(TodosView, _super);
function TodosView() {
TodosView.__super__.constructor.apply(this, arguments);
}
TodosView.prototype.initialize = function() {
this.collection.on('add', this.addOne, this);
return this.collection.on('reset', this.addAll, this);
};
TodosView.prototype.render = function() {
this.addAll();
return this;
};
TodosView.prototype.addAll = function() {
return this.collection.forEach(this.addOne);
};
TodosView.prototype.addOne = function(todoItem) {
var todoView;
todoView = new TodoView({
model: todoItem
});
return this.$el.append(todoView.render().el);
};
return TodosView;
})(Backbone.View);
}).call(this);
class TodosView extends Backbone.View
initialize: ->
@collection.on 'add', @addOne, @
@collection.on 'reset', @addAll, @
render: ->
@addAll()
@
addAll: ->
@collection.forEach @addOne
addOne: (todoItem) ->
todoView = new TodoView model: todoItem
@$el.append todoView.render().el
var TodosView = Backbone.View.extend({
initialize: function(){
this.collection.on('add', this.addOne, this);
this.collection.on('reset', this.addAll, this);
},
render: function(){
this.addAll()
return this;
},
addAll: function(){
this.collection.forEach(this.addOne);
},
addOne: function(todoItem){
var todoView = new TodoView({model: todoItem});
this.$el.append(todoView.render().el);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment