I am trying to create a small application that closes over the delay function and defines a new function using a callback and a wait time. I then wanted to use this newly created inner setTimeout function to take a single parameter that would be run on the callback after the wait time.
function addTwo(num) {
return num + 2
}
const delay = (callback, wait) => {
return setTimeout((value) => callback(value), wait)
}
var delayAddByTwo = delay(addTwo, 100)
console.log(delayAddByTwo(6))
// expected result 8
// actual result --- Uncaught TypeError: delayAddByTwo is not a function
As far as I can tell after the delayAddByTwo = delay(addTwo, 100) the only parameter left to create is the value passed to callback inside the 'inner' setTimeOut function. What am I missing about closure in this example?
setTimeoutwill return its id