定时器VS的setTimeout [英] Timer vs setTimeout

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

问题描述

该文档的flash.utils.setTimeout()状态:

The docs for flash.utils.setTimeout() state:

,而不是使用这种方法,可以考虑   创建一个Timer对象,与   指定的时间间隔,使用1作为   repeatCount参数(这样可将   定时器只运行一次)。

Instead of using this method, consider creating a Timer object, with the specified interval, using 1 as the repeatCount parameter (which sets the timer to run only once).

有谁知道是否有一个(显著)的优势在这样做?使用的setTimeout是轻松了很多,当你只需要推迟1个呼叫。

Does anyone know if there is a (significant) advantage in doing so? Using setTimeout is a lot easier when you only need to delay 1 call.

推荐答案

的setTimeout 实际上使用了定时器的子类,在 SetIntervalTimer ,这是一个内部类。您可以检查通过执行的setTimeout(函数():无效{抛出booom;},1); 。你会看到它的堆栈跟踪。

setTimeout actually uses a Timer subclass, the SetIntervalTimer, which is an internal class. You can check by doing setTimeout(function ():void { throw "booom"; }, 1);. You'll see it in the stack trace.

因此​​,我真的不能看到一个很大的缺点。唯一的区别是,你有2匿名呼叫,而不是一个。 OTOH,在性能至关重要的情况下,你不应该使用(除了一个内部​​定时器),以避免 TimerEvent 对象频繁实例。

As such, I cannot really see a big disadvantage. The only difference is, that you have 2 anonymous calls instead of one. OTOH, in performance critical situations, you shouldn't be using either (except one internal timer) to avoid frequent instantiation of TimerEvent objects.

基本上,我认为这是一个品味的问题。的Adobe决定,AS3的事件系统是shizzle,所以他们推广它。

Basically, I think it's a matter of taste. Adobe decided, the AS3 event system is the shizzle, so they promote it.

这篇关于定时器VS的setTimeout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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