Try running the following code:
function MyClass()
{
this.m_name = "my name";
}
MyClass.prototype.printMyName = function()
{
Log(this.m_name);
return true;
}
function main() {
var myobj = new MyClass();
myobj.printMyName();
_C(myobj.printMyName);
}
The result is:
This does not point to the myobj object in the function when _C ((myobj.printMyName) is called. How can we solve this problem?
Inventors quantify - small dreams ``` function MyClass() { var self = {} self.m_name = "My Name" self.printMyName = function () { Log(self.m_name) return true } return self } function main() { var myobj = MyClass() myobj.printMyName() _C(myobj.printMyName) } ```
Inventors quantify - small dreamsThe reason is that after myobj.printMyName entered _C, the this pointer pointed to ▽ changed.
lightringThank you!