刚刚遇到这个。它并没有真正影响任何事情,但我想知道它为什么会发生。
如果我在firefox上使用firebug运行以下代码:
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。尚未在其他浏览器中测试
答案 0 :(得分:3)
答案 1 :(得分:0)
这是由window.setInterval
自动设置的区间ID。如果存储结果,则可以稍后清除间隔(停止)
var intID = window.setInterval( function(){ alert("I'm annoying!"); }, 10000 );
// this will kill it before it annoys you, :D
window.clearInterval( intID );
window.setTimeout
:
var timeID = window.setTimeout( function(){ alert("I'm annoying!"); }, 10000 );
// this will kill it before it annoys you, :D
window.clearTimeout( timeID );