As you asked for a method using setTimeout
:
function doStuff() {
console.log("hello!");
setTimeout(doStuff, 5000);
}
setTimeout(doStuff, 5000);
But it would probably be better to use setInterval
:
function doStuff() {
console.log("hello!");
}
setInterval(doStuff, 5000);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…