I am facing an issue with my JavaScript class and need some help to resolve it.
MyClass.prototype.foo = function() {
return 0;
}
MyClass.prototype.bar = function() {
return foo() + 1;
}
Unfortunately, when I try to run the program, it throws an error stating that foo() is not defined.
I attempted to fix this by changing the code to:
MyClass.prototype.bar = function() {
return this.foo() + 1;
}
and also tried:
MyClass.prototype.bar = function() {
return MyClass.foo() + 1;
}
However, both changes didn't work and resulted in the same error message.
Ultimately, my goal is to be able to utilize both methods when creating an instance of my class. Can someone advise the best approach to achieve this?
Thank you for your assistance.
edit: I forgot to call the method using the new keyword
var myInstance = new MyClass();