在jquery的setInterval()和setTimeout()中使用hex

You*_*now 4 math jquery scientific-notation

我正在创建一个脚本来检查服务器是否已连接或已经消失.在查看其他人是如何完成它的时候,我意识到有些人在函数内部使用了十六进制.例如 setInterval(l,6E4)

另一个例子

setTimeout(function(){d(window.checknet.config.checkURL)},window.checknet.config.checkInterval)}a=a||{};a.checkURL=a.checkURL||window.location.href;a.checkInterval=a.checkInterval||5E3;a.warnMsg=a.msg||"No Internet connection detected, disabled features will be re-enabled when a connection is detected. ";
Run Code Online (Sandbox Code Playgroud)

这是使用十六进制 a.checkInterval=a.checkInterval||5E3;

为什么使用十六进制而不是普通的十进制数字?

Ant*_*ida 13

这不是十六进制,它是用科学记数法写的数字,6 x 10 4.

= 60.000

由于时间setInterval毫秒为单位,如果你想使用integer秒作为秒,它很容易使用它像:Ne3存在N = seconds.

1e3 = 1000 = 1 second
Run Code Online (Sandbox Code Playgroud)

编辑:

十六进制数字带有前缀0x.