by dstein · 15y ago · 0 comments
class ItemView extends Backbone.View
render: ->
@options.items.each(@renderItem)
renderItem: (item) =>
@el.append item.get("title")
It doesn't make sense because there are magic variables appearing out of nowhere - @options, @el, append -- what are these? I'd have to study the resulting JavaScript to understand what it's really going to do.`this.options` is the options object that was passed when the View was created, and `this.el` is the default DOM element that wraps the View. For more info, see:
Once.
And then you could use shorter, more convenient syntax for the rest of your life. Worth it?
function ItemView() {
this.render = function() {
this.options.items.each(this.renderItem.bind(this));
}
this.renderItem = function(item) {
this.el.append(item.get("title"))
}
}
In this example, I don't see any significant difference as far as readability goes, to be honest. I will note, in case it is not entirely clear, that the use of Backbone in the example is unrelated to CoffeeScript.(This also might be a bad example, but it was based off of code I wrote)
The abridged syntax is just gravy.
In other words, C is somewhat cross platform, and much higher level than assembler. Ruby does way more out of the box than C does.
Coffeescript seems to mostly just be a modified JavaScript syntax, although I have to admit I haven't looked at it that closely.