I came across this TypeScript code that I need help with:
class MyClass {
constructor() {
$("#MyButton").on("click", this.MyCallback);
this.MyMethod();
}
MyCallback = () => {
$.ajax("http://MyAjaxUrl")
.done(function() {
this.MyMethod();
});
}
MyMethod = () => {
// Do some work
}
}
I'm encountering an issue where the JQuery ajax done function is throwing an error stating that "MyMethod is not a function". After investigating the Javascript code, I realized that the issue stems from the fact that "this" does not refer to MyClass at that point in the execution. I'm struggling to find a way to access a reference to the class in this particular scenario.