我正在TypeScript中开发一个与我创建的状态机的对话框 状态机负责启动状态的执行。 当状态结束工作时,他应该执行状态机回调以确定next_state,等等,进入Final_state
提取STATE_MACHINE类的代码
next_state() {
console.log(this)
this.index = this.transitions[this.index][this.current_state.input.event]
this.execute_state()
}
execute_state(): void {
this.current_state.execute(this.next_state)
}
因此execute_state方法通过将next_state方法作为参数来触发current_state的execute方法。 状态调用的最后一条指令调用next_state。
您可以猜到,当我们回到状态机时,“ this”是未定义的
是否有一种简单的方法可以将“ this”还原到触发了execute_state的STATE_MACHINE的出现?