开发者

Why is JSLint complaining about my JavaScript?

开发者 https://www.devze.com 2023-02-25 03:58 出处:网络
{ out = rogueArray[1开发者_开发百科3]; for (var arrayItem in vanWilder) { This is what I am told on JSLint:
{
   out = rogueArray[1开发者_开发百科3];
   for (var arrayItem in vanWilder) 
   {

This is what I am told on JSLint:

Error:

Problem at line 52 character 18: Move 'var' declarations to the top of the function.

for (var arrayItem in vanWilder)

Problem at line 52 character 18: Stopping. (30% scanned).

Implied global: requestOne 19,22,25,27, XMLHttpRequest 19, document 29, out 51

Unused variable: evilVariable 25 "onreadystatechange", redBull 25 "onreadystatechange", wildGoose 25 "onreadystatechange", monkeyWrench 25 "onreadystatechange"

How would I fix this? If not the second error, the first one at least!


Problem at line 52 character 18: Move 'var' declarations to the top of the function.

Because JavaScript doesn't have block scope, and variable definitions are hoisted, Crockford recommends you place all variable definitions at the top of the scope.

Implied global: requestOne 19,22,25,27, XMLHttpRequest 19, document 29, out 51

Because out doesn't have the var keyword to the left, it will be attached to window, essentially making it a global.

Unused variable: evilVariable 25 "onreadystatechange", redBull 25 "onreadystatechange", wildGoose 25 "onreadystatechange", monkeyWrench 25 "onreadystatechange"

You must have defined a variable evilVariable somewhere and not used it.


Remember, Douglas Crockford is a smart man and his JavaScript book is excellent, but take his word and JSLint as one man's recommendations and not the gospel. :)

0

精彩评论

暂无评论...
验证码 换一张
取 消