JSFiddle - React, Tailwind, and code Playground
HTML
<ul id="result"></ul>
JavaScript
// This example is to test the setInterval working principle
// When the loop logic takes too long to response, some of the the interval callbacks will be discarded.
// Refer Doc 1: http://stackoverflow.com/questions/729921/settimeout-or-setinterval/731625#731625
// Refer Doc 2: http://bonsaiden.github.com/JavaScript-Garden/zh/#other.timeouts
// Chinese explanation: http://www.cnblogs.com/sanshi/archive/2011/03/28/1997348.html
var count = 0,
start = new Date(),
interval;
function loop() {
var i, time;
if (count <= 5) {
for (i = 0; i < 1000000000; i++) {}
}
time = parseInt((new Date() - start) / 1000, 10);
$('#result').append("<li>time:" + time + "s - count:" + (++count) + '</li>');
if (count >= 15) {
clearInterval(interval);
}
}
interval = setInterval(loop, 1000);