这是我现在为我的代码收到的唯一错误。'setTimeout'在被定义之前使用了
'setTimeout'在它被定义之前被使用。
它的发生是由于该行:
setTimeout("a()");
我应该做些什么才能通过验证?这是我的全码:
/*global document, window */
function checkTime(i) {
'use strict';
if (i < 10) {
i = "0" + i;
}
return i;
}
function a() {
'use strict';
var oct = ["0", "1", "2", "3", "4", "5", "6", "7"],
octtime,
oct1,
oct2,
oct3,
oct4,
oct5,
oct6,
octvalue,
point = ".",
now = new Date(),
hours = now.getHours(),
minutes = now.getMinutes(),
seconds = now.getSeconds(),
h = checkTime(hours),
m = checkTime(minutes),
s = checkTime(seconds),
totsecs = [hours * 3600 + minutes * 60 + seconds + (now.getTime() % 1000)/1000];
octtime = Math.floor(totsecs/(86400/262144));
oct1 = Math.floor(octtime/32768);
octtime -= 32768 * oct1;
oct2 = Math.floor(octtime/4096);
octtime -= 4096 * oct2;
oct3 = Math.floor(octtime/512);
octtime -= 512 * oct3;
oct4 = Math.floor(octtime/64);
octtime -= 64 * oct4;
oct5 = Math.floor(octtime/8);
octtime -= 8 * oct5;
oct6 = octtime;
octvalue = point + oct[oct1] + oct[oct2] + oct[oct3] + oct[oct4] + oct[oct5] + oct[oct6];
document.getElementById('a').innerHTML = h + ":" + m + ":" + s;
document.getElementById('b').innerHTML = octvalue;
setTimeout("a()");
}
window.onload = a;
前缀http://codebeautify.org/jsval idate。 – jamiestroud69
没有人打算解释*为什么*代码失败:在“a()”中使用括号与*立即调用函数*相同,然后将调用'a()'的返回值传递给setTimeout。你只需要''''''或者更好的'setTimeout(a)'。 –