0

I am coding in JavaScript and was wondering how I would go about queueing functions in an array when called until a execute function is called causing the rest of them to be calculated.

the code that I have for something like this and was just wondering if it would work.

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

I have other functions that follow a simular route, any answers on the matter would be greatly apriciacted.

modzking4
  • 131
  • 10

1 Answers1

1

You need to put the assignment in the callback function.

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

I've removed the x argument, since it's not used for anything.

Barmar
  • 741,623
  • 53
  • 500
  • 612