javascript - setInterval function without arrow function -
i learning react components following documentation https://facebook.github.io/react/docs/state-and-lifecycle.html
why need use arrow function here:
this.timerid = setinterval(() => this.tick(), 1000);
why can't (obviously doesn't work)
this.timerid = setinterval(this.tick(), 1000);
the first argument setinterval
of type function
. if write this:
this.timerid = setinterval(this.tick(), 1000);
…then don't pass function, instead execute function this.tick
, pass value returned function call argument.
you could write this:
this.timerid = setinterval(this.tick, 1000);
if omit parentheses, pass reference this.tick
function, executed setinterval
after 1000 milliseconds.
Comments
Post a Comment