Calling a method on a function definition in coffeescript

前端 未结 4 395
清酒与你
清酒与你 2021-01-17 16:05

How would you translate this snippet of javascript to coffeescript? Specifically I\'m struggling with how to call .property() on the function definition.

4条回答
  •  隐瞒了意图╮
    2021-01-17 16:45

    There are a couple ways to define computed properties. Here are examples of each:

    MyApp.president = Ember.Object.create
      firstName: "Barack"
      lastName: "Obama"
      fullName: (-> 
        @get 'firstName' + ' ' + @get 'lastName'
      ).property('firstName', 'lastName')
    
    MyApp.president = Ember.Object.create
      firstName: "Barack"
      lastName: "Obama"
      fullName: Ember.computed(-> 
        @get 'firstName' + ' ' + @get 'lastName'
      ).property('firstName', 'lastName')
    

提交回复
热议问题