奇怪的随机值作为默认间隔处理程序参数
刚刚遇到这个。它并没有真正影响任何事情,但我想知道为什么会发生这种情况。
如果我在带有 firebug 的 Firefox 中运行以下代码:
setInterval(function(param)
{
console.log("param is %o",param)
},500);
param 似乎被分配了一个模糊的随机值:
param is -2
param is -1
param is -2
param is 1
param is -1
param is 6
param is -1
param is 0
param is -2
param is 2
param is 0
param is 2
param is 0
param is 0
param is 0
[..]
param is 0
param is 0
param is 0
param is 0
param is 0
param is 0
param is 0
param is 911
param is 0
param is 0
param is 0
param is -1
我确实很感激我没有将任何参数传递给 setInterval 来传递给函数,但是为什么 javascript 选择传递这个随机数?
我本来期望未定义或类似的东西......
干杯
p.s.没有在其他浏览器中测试过
Just came across this. It's not affecting anything really but i'm wondering why it's happening.
If I run the following code in firefox with firebug on:
setInterval(function(param)
{
console.log("param is %o",param)
},500);
param seems to be assigned a vaguely random value:
param is -2
param is -1
param is -2
param is 1
param is -1
param is 6
param is -1
param is 0
param is -2
param is 2
param is 0
param is 2
param is 0
param is 0
param is 0
[..]
param is 0
param is 0
param is 0
param is 0
param is 0
param is 0
param is 0
param is 911
param is 0
param is 0
param is 0
param is -1
I do appreciate that I'm not passing any argument to setInterval to pass on to the function, but why does javascript chooses to pass this random number ?
I would have expected undefined or something like that...
Cheers
p.s. Haven't tested in other browsers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它似乎取决于 Firefox 的 CPU 使用率。
我猜想这是从应该调用回调的时间开始的延迟。
编辑:我是对的。这是调用回调的延迟毫秒数。
It appears to be dependent upon Firefox's CPU usage.
I would guess that it's the delay from when the callback should have been called.
EDIT: I was right. It's the number of milliseconds late the callback was called.
它是由
window.setInterval
自动设置的间隔ID。如果存储结果,则可以稍后清除间隔(以停止它),window.setTimeout
也是如此:it's an interval ID automatically set by
window.setInterval
. if you store the result, you can clear the interval later (to stop it)this is also the case with
window.setTimeout
: