jeremyTob
jeremyTob

Reputation: 161

Function passed as reference inside setTimeout

I am studying a bit Angular docs and there's an assignment I do not really get.

setTimeout(() => this.seconds = () => this.timerComponent.seconds, 0);

Does it set a reference of this.timerComponent.seconds to this.seconds? Given that both seconds and timerComponent.seconds are methods, is it equivalent to the following?

 setTimeout(() => { this.seconds = this.timerComponent.seconds }, 0);

Upvotes: 3

Views: 75

Answers (1)

melpomene
melpomene

Reputation: 85767

It's equivalent to

setTimeout(() => { return this.seconds = (() => { return this.timerComponent.seconds; }); }, 0);

It passes a function to setTimeout that, when called, assigns a function to this.seconds that, when called, returns the current value of this.timerComponent.seconds.

Upvotes: 3

Related Questions