Skip to content

Instantly share code, notes, and snippets.

@thmain
Created December 25, 2022 05:30
Embed
What would you like to do?
function customSetInterval (cb, interval) {
return setTimeout( () => {
if (typeof cb == 'function') {
cb()
// Recurse
customSetInterval(cb, interval)
} else {
console.error(new Error('Expecting a function as a callback'))
}
}, interval)
}
function resetCustomSetInterval (id) {
clearTimeout(id)
}
function hello (){
console.log('hello')
}
let id = customSetInterval(hello, 1000)
let id2 = customSetInterval('hello', 1000) // [Error: Expecting a function as a callback]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment