let newSetTimeout = function(fn,delay){ let timer = null; function interval(){ fn(); setTimeout(interval,delay); } interval(); return{ cancel(){ clearTimeout(timer); } } } let newSetInterval = function(fn,delay){ let timer = null; timer = setInterval(()=>{ fn(); clearInterval(timer); },delay); }