0

i am trying to add a set time out function like this and it does not work

setTimeout(myfunction(parameter),200)

meanwhile the code below work but it does not get the job done cause i cant pass a parameter.can anyone explain why ?

setTimeout(myfunction,200)

  • 1
    `myfunction(parameter)` calls the function immediately and passes whatever it returns as callback to `setTimeout`… – deceze Apr 16 '20 at 19:24

1 Answers1

1

Try

setTimeout(function() {
    myfunction(parameter);
}, 200)

You can also use

setTimeout(myfunction.bind(null, parameter), 200);

Ajanyan Pradeep
  • 1,097
  • 1
  • 16
  • 26