Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript setTimeout中的函数不';行不通_Javascript_Node.js_Settimeout - Fatal编程技术网

Javascript setTimeout中的函数不';行不通

Javascript setTimeout中的函数不';行不通,javascript,node.js,settimeout,Javascript,Node.js,Settimeout,有两个函数hello1()和hello2() 在setTimeout中(hello1,3000),延迟3秒后打印“hello1” 但是在setTimeout中(hello2(),3000),它会立即打印“hello2” 我认为这是因为它必须在setTimeout中使用函数名 如果我想在延迟3秒后执行一个带有参数的函数,比如hello(1) 因为我想将参数传递到函数中,所以我不能只在setTimeout中使用函数名,比如setTimeout(hello1,3000)在setTimeout中为函数使

有两个函数hello1()和hello2()

setTimeout中(hello1,3000),延迟3秒后打印“hello1”

但是在
setTimeout中(hello2(),3000),它会立即打印“hello2”

我认为这是因为它必须在setTimeout中使用函数名

如果我想在延迟3秒后执行一个带有参数的函数,比如
hello(1)


因为我想将参数传递到函数中,所以我不能只在setTimeout中使用函数名,比如
setTimeout(hello1,3000)

setTimeout
中为函数使用括号时,它会立即执行

要使用带参数的函数,可以使用任意函数作为超时函数,并在其中调用函数

setTimeout(function() {
    hello(1, 'param');
}, 3000);

非常感谢。我也有同样的问题:)
setTimeout(function() {
    hello(1, 'param');
}, 3000);