将setTimeout()用于大值 [英] Using setTimeout() for large values
问题描述
五分钟后,我正试图让事件发生。我正在使用以下代码:
I'm trying to get an event to fire after five minutes. I'm using the following code:
setTimeout(tweet(name, type), 5 * 60 * 1000);
一段时间后开火,但不会近五分钟(通常两分钟左右,但有时它是即时的。)我究竟做错了什么? (我也尝试将时间设置为 300000
而不是同样的问题。
It is firing after a while, but not nearly five minutes (Usually two minutes or so, but sometimes it's instant.). What am I doing wrong? (I've also tried setting the time to 300000
instead, same problem.
推荐答案
您正在立即调用 tweet
并将其返回值传递给 setTimeout
。
You are calling tweet
immediately and passing its return value to setTimeout
.
您需要将函数传递给 setTimeout
。您还没有包含 tweet $ c $的代码c>,但我会假设它没有
返回
一个函数。
You need to pass a function to setTimeout
. You haven't included the code for tweet
, but I'm going to assume that it doesn't return
a function.
setTimeout(function () { tweet(name, type); }, 5 * 60 * 1000);
这篇关于将setTimeout()用于大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!