JSFiddle - React, Tailwind, and code Playground
by jfriend00
JavaScript
function log(args) {
var str = "";
for (var i = 0; i < arguments.length; i++) {
if (typeof arguments[i] === "object") {
str += JSON.stringify(arguments[i]);
} else {
str += arguments[i];
}
}
var div = document.createElement("div");
div.innerHTML = str;
document.body.appendChild(div);
}
for (var j = 0; j < 30; j += 1) {
(function (index) {
addThisThingtoList(function () {
log("item" + index);
});
})(j);
}
function addThisThingtoList(callback) {
// call callback some time later to simulate
// asynchronous behavior
// could also be calling callback upon completion of ajax call
setTimeout(callback, 1000);
}