javascript - How can I delay a function with parameter? -
this question has answer here:
- calling functions settimeout() 5 answers
i trying make game, machine takes while respond, user knows machine 'deciding' move. need use settimeout()
method, want specify parameter function.
example: settimeout(myfunction('p'), 1000);
. problem when specify parameter, function runs fine, there´s no delay.
when write settimeout(myfunction('p'), 1000);
, myfunction('p')
evaluated , settimeout(returnvalueofmyfunction, 1000)
evaluated.
this code run anonymous function @ correct time:
settimeout(function (){myfunction('p')}, 1000);