Uncaught TypeError: this.firstname is not a function

Uncaught TypeError: this.firstname is not a function

我正在研究knockout js,发生错误 有什么问题吗??

<span data-bind="text: fullname"></span>

<script type="text/javascript">
function AppViewModel() {
  this.firstName = ko.observable('Bob');
  this.lastName = ko.observable('Smith');

  this.fullname = ko.computed(function() {
    return this.firstname() + " " + this.lastname();
  },this);
}

// <!-- ko.applyBindings(viewModel); -->
var vm = new AppViewModel();
ko.applyBindings(vm);
</script>

当我调用它时,

Uncaught TypeError: this.firstname is not a function

发生... 怎么了?

return this.firstname() + " " + this.lastname();

您没有将 firstnamelastname 中的“n”大写。所以尝试这样的事情:

function AppViewModel() {
  this.firstName = ko.observable('Bob');
  this.lastName = ko.observable('Smith');

  this.fullname = ko.computed(function() {
    return this.firstName() + " " + this.lastName();
  },this);
}

// <!-- ko.applyBindings(viewModel); -->
var vm = new AppViewModel();
ko.applyBindings(vm);