• Hi

    I'm having problems to make following code work...

    class GamePlay {
      constructor(game) {
        this.game = game;
      }
      
      activateGameButtons() {
        setTimeout(() => {
          // --- Set reset button watch
          setWatch( (e) => {
            // Check for long press...
            var isLong = (e.time-e.lastTime)>0.4;
            if (isLong) {
              closeApp();
            }
            else this.resetScorePrompt();
          }, BTN2, { repeat: true, debounce: 50, edge: "falling" });
        },100);
      }
      
      resetScorePrompt() {
        clearWatch();
        E.showPrompt("Reset the score\nto 0-0?").then( (reset) => {
          if (reset) {
            this.game.resetScore();
          }
          this.activateGameButtons();
        });
      }
    }
    
    

    After pressing BTN2 I get my prompt and when selecting "yes" or "no" I get the following error (full error in attachment):

    Uncaught SyntaxError: Got => expected ',' at ....
    

    Is there something wrong with my Javascript code ? To me it looks like arrow functions aren't supported in promises. Because in other places, arrow functions work fine. When using 'function (reset) {}' instead of '(reset) => {}' I can enter the function, but then I'm having trouble with the "this scope".
    (I'm a Javascript noob, so it might just be wrong Javascript code I guess :-))


    1 Attachment

    • 2020-06-17 10_41_22-Espruino Web IDE.png
  • Hi,
    reset is a reserved function name. Try a different argument name like this

    E.showPrompt("Reset the score\nto 0-0?").then( (res) => {
          if (res) {
            this.game.resetScore();
          }
          this.activateGameButtons();
        });
    
  • Thanks @Raik, changing the argument name fixed it!

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Arrow function in "showPrompt" promise throws error

Posted by Avatar for skelesp @skelesp

Actions