window.setTimeout无法正常运行

pti*_*rs9 1 javascript window timer settimeout

我试图最终让这个代码工作:

function Timer(callback, delay) {
    var timerId, start, remaining = delay;

    this.pause = function() {
        window.clearTimeout(timerId);
        remaining -= new Date() - start;
    };

    this.resume = function() {
        start = new Date();
        timerId = window.setTimeout(callback, remaining);
    };

    this.resume();
}

var timer;

function onEvent(){
     timer = new Timer(anotherEvent(), 5000);
}
Run Code Online (Sandbox Code Playgroud)

但这不起作用,所以我简化它以查看可能存在的问题,并将其归结为:

var timer;

function event(){
     timer = window.setTimeout(anotherEvent(), 5000);
}
Run Code Online (Sandbox Code Playgroud)

它所做的只是另一个事件().

有任何想法吗?

Que*_*tin 7

anotherEvent作为函数的参数传递.你现在有什么是anotherEvent()调用的函数,并将其返回值作为参数.