【问题标题】:how to queue functions using an array when functions are called [closed]调用函数时如何使用数组对函数进行排队[关闭]
【发布时间】:2019-05-31 20:28:09
【问题描述】:

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

我有这样的代码,只是想知道它是否可以工作。

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

我还有其他功能遵循类似的路线,任何关于此事的答案都会非常感谢。

【问题讨论】:

  • 你好,你可以在这个答案here找到有用的帮助
  • @kemicofa 对不起,我已经删除了我的评论
  • 你说的匿名是什么意思?
  • 我不确定在我为这项任务提供的简报中是否要求它。
  • x 参数到 addNegationTask 的目的是什么?你从不使用它。

标签: javascript node.js


【解决方案1】:

你需要把赋值放在回调函数中。

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

我删除了 x 参数,因为它没有用于任何用途。

【讨论】:

    猜你喜欢
    • 2023-04-06
    • 1970-01-01
    • 2015-12-24
    • 2014-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-19
    相关资源
    最近更新 更多