不多说直接上代码:
var stime = 16,
t;
function fntime() {
stime--;
t = setTimeout(fntime, 1000);
if (stime < 0) {
clearTimeout(t);
return;
}
console.log(stime);
}
var timer = function() {
try {
if (t._idleTimeout < 0) {
fntime();
console.log(1);
}
console.log(2);
} catch (e) {
fntime();
console.log(3);
}
}
timer();
timer();
console.log(t);
console.log(t._idleTimeout);
clearTimeout(t);
console.log(t);
console.log(t._idleTimeout);
timer();
timer();