js this binding setinterval 1

js this binding setinterval

setInterval( this.tick.bind(this), 1000 );

Here is what the above code is Doing:
1. We create a new instance of the Clock class.
2. We call the tick() method every second.
3. We call the tick() method on the clock instance, and bind it to the clock context, so this is equal to the clock object inside of the tick() method.

Similar Posts