本文介绍了在咖啡脚本中的函数末尾添加函数调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于如何将其编写为咖啡脚本的任何想法?

Any ideas on how to write this as 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写这个.

I'm particularly interested in the }.property part of the code. I can't figure out how to write this in coffeescript.

推荐答案

就我个人而言,我喜欢用大括号围绕我的函数:

personally, i like braces around my functions:

Person = Ember.Object.extend(
  firstName: null
  lastName: null
  fullName: (->
    firstName = @get("firstName")
    lastName = @get("lastName")
    firstName + " " + lastName
  ).property("firstName", "lastName")
)

我的头脑可以更好地解析这个 ;-)

my head can better parse this ;-)

这篇关于在咖啡脚本中的函数末尾添加函数调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 11:21
查看更多