1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function renderData(data) {
    var i, tmpContainer;

    tmpContainer = "";
    for (i=0;i<data.length;i++) {
        tmpContainer += '<div> '+data[i]+' </div>';
        if (i % 50 == 0) {
            renderSome(tmpContainer);
            tmpContainer = ""; // "flush" the buffer
        }
    }
    if (tmpContainer) {
        renderSome(tmpContainer);
    }

    // Define this within `renderData` if it needs to refer
    // to any of `renderData`'s variables; the below doesn't
    // and so could be in a utility library somewhere.
    function renderSome(html) {
        // Create closure to preserve value of tmpContainer
        setTimeout(function () {
            document.write(html); // Or appendChild, etc...
        }, 0); // 0 milliseconds
    }
}