Currently with the code below I am getting the error Uncaught ReferenceError: a is not defined
The only way I have found to fix this is by putting this
before the a in the print function. I was wondering if there was a way to avoid this because I think it makes the code messier and is probably unecessary. I know I have to use this
in the constructor by the way although I thought that was only necessary when you had a parameter of the same name.
Class Example{
a;
constructor(a){
//I know I have to put this here to specify which "a" variable
a.this = a;
}
print(){
return a;
}
}
b = new Example("hi);
console.log(b.print());