Pass a function with parameter as an argument to another function in JavaScript