关于如何将其写为coffeescript的任何想法?
Person = Ember.Object.extend({
// these will be supplied by `create`
firstName: null,
lastName: null,
fullName: function() {
var firstName = this.get('firstName');
var lastName = this.get('lastName');
return firstName + ' ' + lastName;
}.property('firstName', 'lastName')
});
我对代码的}.property
部分特别感兴趣。我无法弄清楚如何用coffeescript写这个。
答案 0 :(得分:6)
Person = Ember.Object.extend(
firstName: null
lastName: null
fullName: (->
firstName = @get("firstName")
lastName = @get("lastName")
firstName + " " + lastName
).property("firstName", "lastName")
)
我的脑袋可以更好地解析这个; - )
答案 1 :(得分:-1)
首先jsbeautifier,然后js2coffee:
Person = Ember.Object.extend(
firstName: null
lastName: null
fullName: ->
firstName = @get("firstName")
lastName = @get("lastName")
firstName + " " + lastName
.property("firstName", "lastName")
)
正如他们所说,让你的代码正确。