当 运行 通过机器人框架进行验证时,我如何确保属于 class 验证器所在的属性是可变的?

When running a validation through the bot framework how can I assure properties are mutable that belong to the class the validator is in?

我现在已经遇到过几次这个问题,我想知道我是否可以做些什么来缓解这个问题。

当使用瀑布式对话框或对话框时,您可以将验证器添加到对话框中。这些与您 运行 反对的 class 对话相关联。似乎。但是在运行时,验证器似乎与它所在的 class 分开。

这是一个例子。

 this.addDialog(new TextPrompt(SOME_PROMPT, this.validateSomething))
     .addDialog(new TextPrompt(SOME_PROMPT2, this.validateOtherthing))

然后说你的 class 有一个 属性

public mutableProperty1 = true;

并在验证器中

private async validateSomething(context) Promise<any> {
    if (something happens here) {
       this.mutableProperty1 = false
       return true
    }
    return false
}

但这并没有发生。当出现重试提示时,属性 永远不会突变为所需的结果。为什么会这样,我能做些什么来让它按预期发生突变吗?

我认为这更像是一个 TypeScript/JavaScript 问题,而不是机器人问题。我怀疑问题是 this keyword in the function does not refer to the object you think it does. Whenever you pass a function as a value without calling it, it's usually a good idea to bind 确保 this 的函数引用封闭的 class 实例。

this.addDialog(new TextPrompt(SOME_PROMPT, this.validateSomething.bind(this)))
    .addDialog(new TextPrompt(SOME_PROMPT2, this.validateOtherthing.bind(this)))