How to pass this function into settimeout with parameters?
问题 var test = function(a, b) { return a + b; }; setTimeout(test(2, 3), 3000); it shows some type error 回答1: There are at least two ways to achieve this. The first one just fires the test function inside of a new anonymous function passed as callback to the setTimout . The second one uses .bind to partially apply the test function. var test = function(a, b) { console.log(a + b); return a + b; }; setTimeout(() => { test(2, 3); }, 3000); setTimeout(test.bind(null, 2, 3), 3000); And if you don't