Am I the only one that has trouble parsing this CoffeeScript? I thought the syntax was suppose to be cleaner than plain javascript: MyApp.president = Ember.Object.create fullName: (-> @get('firstName') + ' ' + @get('lastName') ).property('firstName', 'lastName') How the hell am I suppose to read that?
Edit: previous example was incorrect as pointed out by klibertp below. Hopefully they're correct now... it's not exactly a shining example of good coffeescript, but I think this is equivalent js MyApp.president = Ember.Object.create({ fullName: function(){ return this.get('firstName') + ' ' + this.get('lastName'); }.property('firstName', 'lastName') }) I'd probably write it in cs as MyApp.president = Ember.Object.cre…
Anyway, style does matter and were this line written with readability in mind you wouldn't make this mistake.
Also, I would definitely abstract over @get and property:
makeProperty = (attrs...) ->
func = () -> (@get(x) for x in attrs).join(" ")
func.property(attrs...)
MyApp.president = Ember.Object.create(
fullName: makeProperty("firstName", "lastName")
)
The parens after create are not needed, the next indented line should tell us that this is a function with arguments, but I don't mind them here.