记录一下一些常见的JSLint错误,即解决方案。
#1 Expected 'ignore' and instead saw 'e'.
catch (e) {} // Line 7, Pos 20
替换e为ignore
#1 'window' was used before it was defined.
try { window.localStorage.setItem(key, value); } // Line 6, Pos 19
#1 'define' was used before it was defined.
define(['jquery'], // Line 1, Pos 1
#2 'Backbone' was used before it was defined.
var LoginAccount = Backbone.Model.extend({ // Line 29, Pos 28
注意:因为requirejs的缘故
只需要在.jslint.conf中添加"predef" : ["define", "Backbone", "window"]
#2 Unexpected 'in'. Compare with undefined, or use the hasOwnProperty method instead.
if (key in window.localStorage) { // Line 21, Pos 25
解决方法: window.localStorage.hasOwnProperty(key)
#1 Move 'var' declarations to the top of the function.
for (var i in data) { // Line 35, Pos 18
取出变量i
围观我的Github Idea墙, 也许,你会遇到心仪的项目