I have a javascript class and I want to do the following
MyClass.prototype.foo = function() {
return 0;
}
MyClass.prototype.bar = function() {
return foo() + 1;
}
But when I run the program it says foo() is not defined.
I tried
MyClass.prototype.bar = function() {
return this.foo() + 1;
}
and
MyClass.prototype.bar = function() {
return MyClass.foo() + 1;
}
But that doesn't work either and results in the same error.
In the end, I want to use both methods when I create the instance of my class. What is the best way of doing this.
Thanks
edit: I called the method using the new keyword
var myInstance = new MyClass();