(function loop() {
setTimeout(() => {
// Your logic here
loop();
}, delay);
})();Window: setInterval() method / notebook
Window: setInterval() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
class Counter {
constructor() {
this.data = new Map();
}
count(item) {
this.data.set(item, (this.data.get(item) || 0) + 1);
}
}
const counter = new Counter();
counter.count("foo"); // Successfully adds "foo" to the map
setInterval(counter.count, 1000, "bar");
// TypeError: Cannot read properties of undefined (reading 'set') setInterval(() => counter.count("bar"), 1000);
setInterval(function () {
counter.count("bar");
}, 1000);