Created
February 8, 2012 14:09
-
-
Save ericallam/1769792 to your computer and use it in GitHub Desktop.
Comparing js and coffeescript
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
| (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); |
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
| 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 |
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
| 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