I am currently developing an extension for a web-based text editor. However, I am facing some unexpected results due to the class hierarchy in my code.
Despite attempting to relocate the "validate" function to the base class, I have not been successful in resolving the issue.
class BaseClass{
close(): void {
// Performs certain actions
}
save(): void {
// Also performs tasks
}
}
class SubClass extends BaseClass{
close(): void {
this.validate(() => super.close()) // This behaves as anticipated
}
save(): void {
this.validate(() => super.save()) //This leads to the error: Uncaught TypeError: this.validate is not a function
}
validate(callback: () => void){
// Conducts validation checks, and then
if (validationOk) callback()
}
}
The desired outcome is for both the save and close functions within the SubClass to execute the validate function successfully without any errors.