我真的不明白JSLint希望我如何格式化此脚本:
(function ($) {
"use strict";
window.isMobileDevice = function () {
return (window.orientation !== undefined) || (navigator.userAgent.indexOf("IEMobile") !== -1);
};
}());
我收到此错误:
Line is longer than 80 characters.
return (window.orientation !== undefined) || (navigator.userAgent.indexOf("IEMobile") !== -1);
如果我添加换行符:
(function () {
"use strict";
window.isMobileDevice = function () {
return (window.orientation !== undefined) ||
(navigator.userAgent.indexOf("IEMobile") !== -1);
};
}());
我收到此错误:
Expected '(' at column 8, not column 12.
(navigator.userAgent.indexOf("IEMobile") !== -1);
应如何设置换行符的格式?
答案 0 :(得分:0)
就像它告诉您的那样:Expected '(' at column 8, not column 12.
。 ; ^ D
将那条线向后移动四个空格,您真是个黄金。
这对我来说JSLint.com有毛病:
/*jslint browser*/
(function () {
"use strict";
window.isMobileDevice = function () {
return (window.orientation !== undefined) ||
(navigator.userAgent.indexOf("IEMobile") !== -1);
};
}());
请注意,我还必须删除未使用的参数$
。
我认为这是我说JSLint非常有见识的地方,但是幸运的是,这是我们可以根据需要更改它的地方。如果您设置了the "white
space mess" directive,则您的代码(减去$
)就可以了。
/*jslint browser, white*/
(function () {
"use strict";
window.isMobileDevice = function () {
return (window.orientation !== undefined) ||
(navigator.userAgent.indexOf("IEMobile") !== -1);
};
}());