|
|
|
|
|
by cubicle67
4862 days ago
|
|
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.create
fullName: (
-> "#{@get 'firstName'} #{@get 'lastName'}"
).property('firstName', 'lastName')
(ie multi line rather than a single line) but that's very much just stylistic choice. It's also a lousy example of the benefits of cs as the cs version doesn't add any benefit over the plain js one. |
|
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:
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.