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

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -