Take a look at the code snippet below:
class Person{
firstname = ko.observable<string>();
lastname: ko.observable<string>();
fullname = ko.computed(()=>{
// Breakpoint here
return this.firstname() + ' ' + this.lastname();
});
During debugging in Visual Studio 2013, I noticed that when I set a breakpoint and examine the value of this
using watch or immediate window, it displays as window
instead of an instance of the person object. As a result, this.firstname
returns undefined
.
Upon reviewing the generated JavaScript code, I realized that I should be checking the value of _this
instead of this
.
Even though the code executes without errors, it took me some time to realize that the actual value of this
is accessible through _this
.
Question: Is there a mistake in how I am using class properties that leads to this discrepancy in the value of this
? Or is it possibly a bug? Could it be intentional for certain reasons?