Blog

Blog

PHODAL

JSLint 错误笔记

记录一下一些常见的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: @phodal     微博:@phodal     知乎:@phodal    

微信公众号(Phodal)

围观我的Github Idea墙, 也许,你会遇到心仪的项目

QQ技术交流群: 321689806
comment

Feeds

RSS / Atom

最近文章

关于作者

Phodal Huang

Engineer, Consultant, Writer, Designer

ThoughtWorks 技术专家

工程师 / 咨询师 / 作家 / 设计学徒

开源深度爱好者

出版有《前端架构:从入门到微前端》、《自己动手设计物联网》、《全栈应用开发:精益实践》

联系我: h@phodal.com

微信公众号: 最新技术分享

标签