非常基本的setTimeout问题 [英] Very basic setTimeout Question

查看:52
本文介绍了非常基本的setTimeout问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个非常基本的问题 - 但是在找到20分钟的

之后我找不到答案。


如果你编码的话喜欢:


函数set_It(){

setTimeout(''Request_Complete(" apple",-72)'',5000)

}


并调用它50次,是否会导致问题,因为你没有

用var声明它并使用clearTimeout销毁它之后

每次使用?


我很确定你不必清除超时 - 因为它只是

发生一次(与间隔不同)或var它,但我想确定




事情似乎工作正常,但我正在构建一个复杂的应用程序

并且不想要一些基本的东西来进一步搞砸了

行...


谢谢,

蓝杏

This is a very basic question -- but I can''t find the answer after
looking for 20 minutes.

If you code something like:

function set_It() {
setTimeout(''Request_Complete("apple", -72)'',5000)
}

and call it 50 times, will it cause problems because you are not
declaring it with a var and destroying it with a clearTimeout after it
is used each time?

I am pretty sure you don''t have to clear a timeout -- since it only
happens once (unlike an interval), or "var" it, but I want to make
sure.

Things seem to be working fine, but I am building a complex application
and don''t want something basic to screw things up further down the
line...

Thanks,
Blue Apricot

推荐答案



不,可以安全地使用它,没有var / id为它,var为

它是可选的,使用clearTimeout()或只是为了检查它是否运行
,但只是为了拨打50个电话,好的。


Danny

No, is safe to just use it as is, with no var/id for it, the var for
it is optional to use clearTimeout() or just to check if it''s
running, but just to make 50 calls regardless, is ok.

Danny


好的,这就是我的想法。谢谢。


为了清楚起见,即使我快速连续拨打了50次,

所以timeOuts是重叠,它会还好吗?对吧?


谢谢,

BA

Ok, that is what I thought. Thanks.

And just to be clear, even if I called it 50 times in rapid succession,
so the timeOuts are "overlapping", it will still be fine, right?

Thanks,
B.A.


bl ************ @ gmail.com 上面说4 / 16/2006 1:40 AM:
bl************@gmail.com said the following on 4/16/2006 1:40 AM:
这是一个非常基本的问题 - 但是在找了20分钟之后我找不到答案。

函数set_It(){
setTimeout(''Request_Complete(" apple", - 72)'',5000)
} <并且调用它50次,是否会引起问题因为你没有用var声明它并且在每次使用
后用clearTimeout销毁它?


不,但我认为你指的是用var声明它:


var myTimeout = setTimeout(..)


将它分配给一个变量的唯一理由就是清除它。

但不是在使用之后,但是如果要清除它并取消

定时事件。


你将遇到更多setTimeout问题(比缺少声明

a var)改为使用window.setTimeout。


但是,我从未见过需要快速连续调用50次超时。

调用一次超时,超时调用一个函数执行另一个函数
50次。结果是一样的,但你的开销是

不一样。

我很漂亮确定你不必清除超时 - 因为它只发生一次(不像间隔),或var它,但我想确定
This is a very basic question -- but I can''t find the answer after
looking for 20 minutes.

If you code something like:

function set_It() {
setTimeout(''Request_Complete("apple", -72)'',5000)
}

and call it 50 times, will it cause problems because you are not
declaring it with a var and destroying it with a clearTimeout after it
is used each time?
No, but I assume you are referring to declaring it with a var as such:

var myTimeout = setTimeout(..)

The only reason to assign it to a variable is indeed to clear it out.
But not after it is used, but if you want to clear it out and cancel the
timed event.

You will have more problems with setTimeout( than the lack of declaring
a var to it. Use window.setTimeout instead.

But, I have never seen a need to call 50 timeouts in rapid succession.
Call one timeout, have that timeout call a function that executes
another function 50 times. The results are the same but your overhead is
not the same.
I am pretty sure you don''t have to clear a timeout -- since it only
happens once (unlike an interval), or "var" it, but I want to make
sure.




仅在您之前要清除它时它发生了。


忽略Danny,我们一直在努力教他一年多如何将
正确地发布到Usenet和特别是这个组。 br />

-

兰迪

comp.lang.javascript常见问题 - http://jibbering.com/faq &新闻组每周

Javascript最佳实践 - http://www.JavascriptToolbox .com / bestpractices /



Only if you want to clear it before it happens.

Ignore Danny, we have been trying to teach him for over a year how to
properly post to Usenet and this group in particular.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


这篇关于非常基本的setTimeout问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆