给定以下coffeescript。
App.Whatever = Em.ArrayController.extend
clean: Em.computed ->
@get('content').filterBy('clean', true)
.property 'content'Coffeescript < 1.7将正确地输出:
App.Whatever = Em.ArrayController.extend({
clean: Ember.computed(function() {
return this.get('content').filterBy('clean', true);
}).property('content')
});现产出:
App.Whatever = Em.ArrayController.extend({
clean: Ember.computed(function() {
return this.get('content').filterBy('clean', true);
})
}).property('content');这好像是外卖。我是遗漏了什么,还是必须重写所有的计算属性?
示例
发布于 2014-02-01 12:11:07
我认为您对链接属性使用coffeescript的方式是没有文档的。我认为链接的官方方法是使用括号显式定义属性的附加位置.
App.Whatever = Em.ArrayController.extend
clean: Em.computed( ->
@get('content').filterBy('clean', true)
).property 'content'或者,如果你真的想避免括号,你可以这样写它
App.Whatever = Em.ArrayController.extend
clean:
Em.computed ->
@get('content').filterBy('clean', true)
.property 'content'以上两个示例都编译为
App.Whatever = Em.ArrayController.extend({
clean: Em.computed(function() {
return this.get('content').filterBy('clean', true);
}).property('content')
});更新: CoffeeScript 1.7新特性
从医生那里..。Leading . now closes all open calls, allowing for simpler chaining syntax.
$ 'body'
.click (e) ->
$ '.box'
.fadeIn 'fast'
.addClass '.active'
.css 'background', 'white'会输出..。
$('body').click(function(e) {
return $('.box').fadeIn('fast').addClass('.active');
}).css('background', 'white');https://stackoverflow.com/questions/21495333
复制相似问题