Message from JavaScript discussions

April 2019

— I know async await but never used

— 

I would prefer Fastify because it supports async await and it faster than express. Most express modules also work with fastify

— It works for me. displayTime is showing a different value every second.

— Yes but does it update newGame.startTime property

— That's what I need to achieve

— Yes it does. But, when your calling the play method it evaluates that expression and passes it like a value. That’s why it never updates that value. But if instead of func you put in the console.log a this.startTime you should see the new value.

If I understood well maybe you want something like

newGame.play(() => newGame.startTime)

and inside of the console you execute the argument func.

Message permanent page

— Https://pastebin.com/mcSB6ExR

— I need to think on that, I didn't understand what you ment in 100 percent but it's not your fault, I'm still new in this

Message permanent page

— I basically need an easy access everywhere in the js file to the updated version of newGame.startTime

Message permanent page

— Ok, you will always have an updated version, but if you pass it to a function it will stay the same because it will not pass a “pointer” and instead will evaluate the expression at that time.

You could pass the reference of your object.

newGame.play(newGame)

play(game) {
this.interval = setInterval(() => {
console.log(this.displayTime())
console.log(game.startTime)
this.startTime++
return this.startTime
}, 1000)
}

Message permanent page

— I think I got your point, I will give it a try and hopefully it will get me the correct results

— elxris thanks a lot for the help!