如何在调用函数时使用数组对函数进行排队



我正在用JavaScript编码,想知道在调用时我将如何在数组中排队函数,直到调用执行函数导致计算其余函数。

我为这样的东西准备的代码,只是想知道它是否有效。

addNegationTask(x)
{
   this.value = this.value * -1
   // this adds the equation to the array
   this.tasks.push(x => value * -1)
   return this.value;
}

我还有其他遵循模拟路线的功能,关于此事的任何答案都将非常珍贵。

您需要将赋值放在回调函数中。

addNegationTask()
{
   // this adds the equation to the array
   this.tasks.push(() => this.value *= -1)
}

我已经删除了x参数,因为它不用于任何用途。

最新更新