You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • Without a complete mini example to look at I can't be sure, but any function that is defined (even arrow functions) will contain a link to the scope they were defined in. Espruino isn't smart enough to figure out when the function is defined if it actually references any local variables.

    So likely:

    setTimeout(function() {
      this.printMem();
    }, 3000);
    setTimeout(this.printMem, 3000);
    

    Will print two very different results. Could that be it?

  • The print mem function was defined within the class instance which was running for the entire length of the program so any variables local to that should stay locked in memory so this shouldn't be a factor.

    In your example "this" could have change so they could print different results if printMem was different. Arrow functions were introduced to guarantee "this" stays the same. So

    const app = new App();
    app.setup() //"this" will be instance of the App
    app.printMem() // will be same as this.printMem inside setup
    
About

Avatar for Gordon @Gordon started