我ArticleDialogBox
在构造函数中有名称为 的类我创建了实现某些接口的匿名类 我想访问名称为articleSelected
from的方法ArticleDialogBox
如何访问它?
export class ArticleDialogBox {
private articlesListBox: ListBox = new ListBox();
private titleTextBox: TextBox = new TextBox();
private saveButton: Button = new Button();
constructor() {
this.articlesListBox.addEventHandler(new class implements EventHandler {
handle(): void {
//how can i access a method in ArticleDialogBox.articleSelected();
}
});
}
articleSelected(): void {
this.titleTextBox.setContent(this.articlesListBox.getSelection());
this.saveButton.setEnabled(true);
}
}
一个典型的解决方案是这样的:
constructor() {
const _self = this;
this.articlesListBox.addEventHandler(new class implements EventHandler {
handle(): void {
_self.articleSelected();
}
});
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句