简体   繁体   中英

How can I make a javascript function which will undo the task of the previous function? [on hold]

I am trying to create a simple React app, but I am having trouble with "undo" functionality.

Example:

  1. The current score is shown. Let's say 1000
  2. Two buttons increase and decrease respectively Add and Subtract from the score. Let's say by 20 and 40
  3. How do I create an undo button that will undo the last action(s)?

This should occur:

  • Start => 1000
  • Increase => 1020
  • Decrease => 980
  • Undo => 1020
  • Undo => 1000

I guess that you can store the value of the previous score in a variable “preciousScore”. When you click on the undo button it set the score = previousScore

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM