function sum(x, y) { console.log(x + y); } setTimeout(sum, 1000, 1, 3);
定时器启动时候,第三个以后的参数是作为第一个func()
的参数传进去。
var timeoutID; function delayedAlert() { timeoutID = window.setTimeout(window.alert, 2*1000, 'That was really slow!'); } function clearAlert() { window.clearTimeout(timeoutID); }