I'm quite new to javascript/typescript. I have this code and I want to call a class function inside an event handler. The problem is that this
is not what I expected.
class MyClass {
private textInput: TextView;
private _presenter: DateOptionPresenter;
constructor(properties: { presenter: DateOptionPresenter } & CompositeProperties) {
super(properties);
this._presenter = properties.presenter;
this.createUI();
}
private createUI() {
this.append(
this.textInput = new TextView({
left: 5, right: 5, top: 5, bottom: 5
}).on({tap: this.showDateDialog})
);
}
private showDateDialog() {
let selectedDate = new Date();
new DateDialog({
date: selectedDate
}).on('select', (date) => this._presenter.fill(date))
.open();
}
}
So, In the last function showDateDialog(), when I call this
it's in the TextView context instead of the MyClass, and this._presenter
is undefined.
How can I access _presenter in there ?