我如何在初始化类后调用要分配的方法

时间:2019-07-14 00:13:18

标签: typescript

每次尝试更改进度时,我都试图调用一个方法(将在初始化后声明)

class Task {

  Constructor(){
    this.DoTask();
    }
// I want to set this outside class after the instance is created 

public OnProgress(p: number){}



public DoTask(){
     prog = progress({}, this.OnProgress.bind(this));

// the task is being performed here
     ...
      .pipe(prog) 
      .RemainingOFTransforms()
   }

}

const MyTask = new Task();
MyTask.OnProgress = (p: number) => {
   console.log(p) // this should log all the progress numbers as it is constantly changing
}

我希望每次更改进度时都会调用MyTask.OnProgress,但只会调用一次

0 个答案:

没有答案