never write code on no sleep. that code sample should be : timers= (function () { var timers = []; var id=0; timer=function (f,t) { timers.push({func:f, interval:t, id:id++}); return id; } return timers; }) runScript("env.js"); runScript("program.js"); ev=getEvents(); while (!programHasQuit()) { handleEvents(timers,ev); }