0

这里有什么问题?

ExecJS::ProgramError: Error: Parse error on line 11: Unexpected '.'

。咖啡

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

原始.js

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')
});
4

1 回答 1

0

调用方法时需要添加大括号。

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

确实,它们在 Coffeescript 中是可选的,但在这种情况下,我认为您需要显式添加它们。至少这是我编译它的唯一方法。也许 Coffeescript 专家可以解释为什么。

于 2013-02-14T23:16:42.940 回答