Coffeescript: Accessing properties of anonymous functions
I'm following the Getting Started guide at emberjs.com, but attempting to
write the code in Coffeescript as I go.
I'm a little stumped by this piece of code, however:
Todos.TodoController = Ember.ObjectController.extend({
isCompleted: function(key, value){
var model = this.get('model');
if (value === undefined) {
// property being used as a getter
return model.get('isCompleted');
} else {
// property being used as a setter
model.set('isCompleted', value);
model.save();
return value;
}
}.property('model.isCompleted')
});
the second-last line, }.property('model.isCompleted'), is calling a method
on the anonymous function just defined.
Is there an easy, idiomatic way to do this in Coffeescript?
Currently, I've hoisted the function def myself:
c = (key, value) ->
model = this.get 'model'
unless value?
model.get 'isCompleted'
else
model.set 'isCompleted', value
model.save()
value
Todos.TodoController = Ember.ObjectController.extend(
isCompleted: c.property('model.isCompleted')
)
but I feel I shouldn't have to do this. Attempting to chain the method
calls (the way other things are chained in CS) gave rise to syntax errors
instead.
No comments:
Post a Comment