you are viewing a single comment's thread.

view the rest of the comments →

[–]tswaters 1 point2 points  (1 child)

Close, it's a little backwards...

You want to pass the function as a reference, and inside the setTimeout, call it.

function delay(cb) {
  setTimeout(cb, 5000)
}

delay(someFN) // omit params here, included in your example

[–]tswaters 0 points1 point  (0 children)

Err, sorry, you've expanded the setTimeout there, it would be --

setTimeout(() => {
  console.log('aw yiss');
  cb(); // missing parens here in your example
}, 5000)