javascript - JSLint 换行格式
问题描述
我真的不明白 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);
换行符应该如何格式化?
解决方案
就像它告诉你的那样:Expected '(' at column 8, not column 12.
。;^D
将那条线向后移动四个空格,你就是金色的。
这在 JSLint.com 上对我来说是lints:
/*jslint browser*/
(function () {
"use strict";
window.isMobileDevice = function () {
return (window.orientation !== undefined) ||
(navigator.userAgent.indexOf("IEMobile") !== -1);
};
}());
请注意,我还必须删除该参数$
,因为它没有被使用。
但是你可以覆盖它......
我认为这就是我说 JSLint非常固执己见的地方,但幸运的是,这是我们可以将其更改为按您想要的方式工作的地方。如果你设置了“ white
space mess”指令,你的代码(减去$
)就可以了。
/*jslint browser, white*/
(function () {
"use strict";
window.isMobileDevice = function () {
return (window.orientation !== undefined) ||
(navigator.userAgent.indexOf("IEMobile") !== -1);
};
}());
推荐阅读
- swift - 在视图控制器上显示用户电子邮件提供可选的“电子邮件地址”
- google-sheets - 将 finviz.com 的股息插入 Google 表格有什么问题?
- javascript - Javascript 循环中的正确范围和事件处理
- python - Django 模型有一个意外的关键参数
- python - 需要在文件夹中获取最近上传的图像名称。我希望在同一个文件夹中重命名并替换它
- javascript - Webpack 相关错误 - 未捕获(承诺中)错误:找不到模块 './theme/textmate'
- python - 在 moive.py python 中设置音频质量(音频大小为 1.50 GB,当我将其转换为视频时,它只有 500 MB)
- python - 序列或迭代器中的 for 循环
- dns - 即使在 Cloudflare 规则中进行了正确的配置设置,也会出现 301 重定向错误
- amazon-web-services - 是否可以将 SNS 消息从全球 AWS 账户发布到中国账户的 SQS 队列