Knockout.js 为什么我们通过';这';在韩国

Knockout.js 为什么我们通过';这';在韩国,knockout.js,knockout-2.0,Knockout.js,Knockout 2.0,我正在从它的官方网站学习淘汰赛,这里是我从网站上获取的教程 // This is a simple *viewmodel* - JavaScript that defines the data and behavior of your UI function AppViewModel() { this.firstName = ko.observable(''); this.lastName = ko.observable("Bertington"); this.fullName = ko.com

我正在从它的官方网站学习淘汰赛,这里是我从网站上获取的教程

// This is a simple *viewmodel* - JavaScript that defines the data and behavior of your UI
function AppViewModel() {
this.firstName = ko.observable('');
this.lastName = ko.observable("Bertington");
this.fullName = ko.computed(function() {
return this.firstName() + " " + this.lastName();    
}, this);
}

// Activates knockout.js
ko.applyBindings(new AppViewModel());
我想问,将这个作为参数传递给计算函数的目的是什么

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

谢谢

< P>因为在JavaScript <强> > 绝大多数时间不是你所期望的,它来自C,C++或java开发者POV。
this参数确保当计算出的可观测值的新值被计算时,this实际上绑定到viewmodel,而不是调用方法(例如事件处理程序)的此上下文。

您是否阅读了上的管理“this”部分?还有什么不清楚的吗?您也可以通过添加“var self=this”作为ViewModel函数的第一行来绕过这一点。然后,您在通常会提到“this”的任何地方都提到“self”,包括在计算函数中。