I'm using V8 in conjuction with c++ and native window setInterval functon is not defined.
What would be an algorythm to create something like native setInterval but in pure js?
I'm using V8 in conjuction with c++ and native window setInterval functon is not defined.
What would be an algorythm to create something like native setInterval but in pure js?
Assuming setTimeout is available (not probable, but you did not specify that):
function setInterval(fn, t) {
let id = {};
function wrapper() {
id.timeout = setTimeout(wrapper, t);
fn.apply(this, arguments);
}
id.timeout = setTimeout(wrapper, t);
return id;
}
function clearInterval(id) {
clearTimeout(id.timeout);
}