Check my code below, I am just lost here why am I getting this error. Any suggestion please. Here I have made a class test and added two methods check and nextfn. I am calling check from nextfn.
var test=function(){}
test.prototype.check=function()
{
console.log("hello from checking");
}
test.prototype.nextFn=function(){
check();
console.log("Hello from nextfn");
}
Next
var t=new test();
t.nextfn();
The error is
Uncaught ReferenceError: check is not defined(…)
Now consider another scenario;
test.prototype.anotherFn=function()
{
var p=new Promise(function(){
this.check();
})
}
Now also getting same error;
Uncaught ReferenceError: check is not defined(…)
When calling
var t=new test();
t.anotherFn();
this.check();new test()instead ofnew text()checkmethod was put on the prototype of test.nextFnis part of the same prototype,thisis a keyword referring to the parent/prototype.