Basicly, what happens is that your loop runs on the UI thread, and i dont believe there is a way to create a thread in JS.
so, as long as your loop runs steadily, the drawing events are retained.
There might be solutions. Now, i can't validate what i'm suggesting but i'm sure other folks will put you back on track.
1) There might be some kind of paint function .. something like output.redraw or output.refresh, etc etc.
2) If not, its possible (althought im not sure) that there so kind of "yield" or "doevents" .. something like that.
Its all just theorical since i havent fiddled with JS for a long time.