I’ve been seeing the syntax:
var module = {
func: function(value) {
some code;
}.func2("value");
}
cropping up in various places, as am wondering how this is done. I remember seeing an article about it a while back, but can’t find it now. Whatever I try .func2("value") just trows syntax errors.
For example, take a look at SproutCore’s intro to their TemplateView.
Todos.StatsView = SC.TemplateView.extend({
remainingBinding: 'Todos.todoListController.remaining',
displayRemaining: function() {
var remaining = this.get('remaining');
return remaining + (remaining === 1 ? " item" : " items");
}.property('remaining').cacheable()
});
Seems like it would be a useful tool to give users when writing factories.
Thanks.
You can add properties to Function’s prototype and then chain function definitions. For example:
When setValue is defined the trigger function is called within the scope of the anonymous function it’s chained to, and setValue is assigned the value returned by trigger. In this case we’re just alerting that setValue is being called, but this opens some very cool possibilities.
Pretty slick.