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

Javascript 调用函数时如何使用数组对函数进行排队,javascript,node.js,Javascript,Node.js,我正在用JavaScript编写代码,我想知道调用时如何在数组中对函数进行排队,直到调用一个execute函数,从而计算其余的函数 我的代码是这样的,我只是想知道它是否能工作 addNegationTask(x) { this.value = this.value * -1 // this adds the equation to the array this.tasks.push(x => value * -1) return this.value; } 我还有

我正在用JavaScript编写代码,我想知道调用时如何在数组中对函数进行排队,直到调用一个execute函数,从而计算其余的函数

我的代码是这样的,我只是想知道它是否能工作

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参数,因为它不用于任何用途。

您好,您可以在这个答案中找到有用的帮助@kemicofa sorry my bad,我已经删除了我的评论你所说的匿名是什么意思?我不确定这是我在为这项任务所做的简报中被要求的东西。x参数addNegationTask的目的是什么?你从不使用它。