javascript - Calling a function with parameters inside another function -


i trying build kind of scheduler function, able call function parameters @ random instants in time. here attempt, using javascript:

function schedulefunction(t, deltat, functionname) {      var timeout;     var timeoutid;      function scheduler() {       functionname()        cleartimeout(timeoutid);       timeout = math.trunc(math.random() * 2 * deltat - deltat) + t;       timeoutid = settimeout(scheduler, timeout);     }      scheduler();    } 

this function works if let call function doesn't require parameters. instance:

function printsomething() {         console.log("printing something...");       }  schedulefunction(1000, 500, printsomething); 

unfortunately, function doesn't allow call function parameter, - example:

function print(string) {         console.log(string); }  schedulefunction(1000, 500, print("hello world!")); 

how should edit scheduler function in order obtain kind of result, if possible?

simple

schedulefunction(1000, 500, function() {   print("hello world!") }); 

Comments