Shouldn't timers be specified?

Brandon Benvie brandon at
Sat Jan 21 21:36:45 PST 2012

For reference, here's the start of an es-discuss thread on the topic from
March 2011:

Here's a reference on implementing timer functions in Rhino:

You can use java.util.Timer<>
 and java.util.TimerTask<>
roll your own set/clear Timeout and set/clear Interval functions:

var setTimeout,

(function () {
    var timer = new java.util.Timer();
    var counter = 1;
    var ids = {};

    setTimeout = function (fn,delay) {
        var id = counter++;
        ids[id] = new JavaAdapter(java.util.TimerTask,{run: fn});
        return id;

    clearTimeout = function (id) {
        delete ids[id];

    setInterval = function (fn,delay) {
        var id = counter++;
        ids[id] = new JavaAdapter(java.util.TimerTask,{run: fn});
        return id;

    clearInterval = clearTimeout;


Looking for the Spidermonkey equivalent currently. Regardless, it
seems like something that needs to be implemented at the language
level, and has wide support for it. There's a lot on the table for ES6
and it's pretty late in the game (well after technical feature freeze)
so I definitely see why it wouldn't make the cut. But if not for ES6,
this needs to be in ES next text, and as something already implemented
in nearly all JS envs, simply informally agreeing on the fundamentals
would be enough to get it most of the way there implementation-wise in
most implementations.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list