首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >coffeescript 1.7破坏了我的ember.js计算属性

coffeescript 1.7破坏了我的ember.js计算属性
EN

Stack Overflow用户
提问于 2014-02-01 07:19:17
回答 1查看 457关注 0票数 3

给定以下coffeescript。

代码语言:javascript
复制
App.Whatever = Em.ArrayController.extend
  clean: Em.computed ->
    @get('content').filterBy('clean', true)
  .property 'content'

Coffeescript < 1.7将正确地输出:

代码语言:javascript
复制
App.Whatever = Em.ArrayController.extend({
  clean: Ember.computed(function() {
    return this.get('content').filterBy('clean', true);
  }).property('content')
});

现产出:

代码语言:javascript
复制
 App.Whatever = Em.ArrayController.extend({
  clean: Ember.computed(function() {
    return this.get('content').filterBy('clean', true);
  })
 }).property('content');

这好像是外卖。我是遗漏了什么,还是必须重写所有的计算属性?

示例

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-01 12:11:07

我认为您对链接属性使用coffeescript的方式是没有文档的。我认为链接的官方方法是使用括号显式定义属性的附加位置.

代码语言:javascript
复制
App.Whatever = Em.ArrayController.extend
  clean: Em.computed( ->
    @get('content').filterBy('clean', true)
  ).property 'content'

或者,如果你真的想避免括号,你可以这样写它

代码语言:javascript
复制
App.Whatever = Em.ArrayController.extend
  clean:
    Em.computed ->
      @get('content').filterBy('clean', true)
    .property 'content'

以上两个示例都编译为

代码语言:javascript
复制
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.

代码语言:javascript
复制
$ 'body'
.click (e) ->
  $ '.box'
  .fadeIn 'fast'
  .addClass '.active'
.css 'background', 'white'

会输出..。

代码语言:javascript
复制
$('body').click(function(e) {
  return $('.box').fadeIn('fast').addClass('.active');
}).css('background', 'white');
票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21495333

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档