mik*_*ana 16 javascript syntax for-loop jshint
以下代码:
var things = {'foo':'bar'}
for ( thing in things ) {
console.log(thing)
}
Run Code Online (Sandbox Code Playgroud)
在jshint中始终产生以下错误:
Bad for in variable 'thing'.
Run Code Online (Sandbox Code Playgroud)
我不明白是什么让"东西"变量"变坏" - 正如你所看到的,它并没有被其他任何地方使用.我应该做些什么来使jshint不认为这是一个错误?
Dut*_*432 25
他们总是 - 如果他们没有宣布.尝试添加var
if thing
先前未声明.
for ( var thing in things ) {
console.log(thing)
}
Run Code Online (Sandbox Code Playgroud)
要么
var thing;
//more code
for ( thing in things ) {
console.log(thing)
}
Run Code Online (Sandbox Code Playgroud)