Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有办法清除 asetTimeout而无需将其存储在变量中然后将其传递给clearTimeout?
setTimeout
clearTimeout
或者以某种方式setTimeout返回一个 id 而不是一个对象,我会传递给它clearTimeout?
function myTimeout(f, ms) { var id = setTimeout(f, ms); return { cancel : function() { clearTimeout(id); } }; } var t = myTimeout(somefunc, 5000); // ... t.cancel();