setInterval / setTimeout返回值 [英] setInterval/setTimeout return value

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

问题描述

两个问题:


  1. 如何从 setInterval 和 setTimeout (用于清除计时器的那些)计算?

  1. How is the value returned from setInterval and setTimeout (the ones used to clear the timers) calculated?

两者都有可能在运行时返回相同值的函数?
例如:

Is it possible for both the functions to return the same value during runtime? For example:

var a = setInterval(fn1,1000);

var b = setTimeout(fn2,1000);

a b 是否可以拥有相同的值?

Is it possible for a and b to have the same value?

第一个问题更多的是我的知识问题,但第二个更重要。

The first one is more of a for-my-knowledge question, but the second one is more important.

推荐答案

返回可用于取消计时器的值。因此,它们似乎不太可能返回相同的值(除非它们重用值并且其中一个计时器已被取消)

Returns a value which can be used to cancel the timer. So, it would seem unlikely that they return the same value (unless they are reusing values and one of the timers has already been cancelled)

Mozilla声明它的DOM级别为0,但不是规范的一部分。(查看底部的页面)

我有一个更好的参考:

Nabble 说:


SetTimeout和setInterval来自
原始Javascript规范,
pre-ECMA。该规范在任何地方都不是官方标准化的
,但所有网络浏览器都支持

以及
Javascript语言的大多数实现。 (包括
ActionScript。)

SetTimeout and setInterval are from the original Javascript specification, pre-ECMA. That specification is not officially standardized anywhere, but it is supported by all web browsers and most implementations of the Javascript language. (Including ActionScript.)

ECMA之前的规范通常称为
DOM-0API。由于他们之前从未标准化过
,所以
对于HTML5来说是有意义的,最终规定
未弃用的API尝试
来提供一致的环境
浏览器。特别是当
最近的事件已经证明,b $ b是那些喜欢实施标准字母
的公司,而不是
精神。

The pre-ECMA specs are often known as the "DOM-0" APIs. Since they have never been standardized before, it makes sense for HTML5 to finally spec the non-deprecated APIs in an attempt to provide a consistent environment across browsers. Especially when recent events have proven that there are companies who like to implement the letter of the standard, but not the spirit.

阅读原始规范此处,或来自 Sun (谁是早期的JavaScript代言人。)

Read the original spec here, or from Sun (who was an early endorser of JavaScript).

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

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