打字稿中主类的访问方法

莫森

ArticleDialogBox在构造函数中有名称为 的类我创建了实现某些接口的匿名类 我想访问名称为articleSelectedfrom的方法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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章