剛剛遇到此問題。這並不影響任何事情,但我想知道爲什麼會發生。奇怪的隨機值作爲默認間隔處理程序參數
如果我在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選擇傳遞這個隨機數?
我本來期望未定義或類似的東西...
乾杯
附:沒有在其他瀏覽器上測試過
順便說一句,你可以更簡單地測試這個像這樣:'setInterval(console.log,500)'。 – SLaks