JSLint(Javascript 验证器网站)- 错误!隐含全局:
我刚刚在 JSLint 测试了我的自定义画廊脚本。除了一个错误之外,所有错误都已解决。 隐含的全局错误..这真的是一个错误吗?我可以忽略它还是应该努力解决这个错误..?
感谢您的回复!
Error:
Implied global:
<bunch of vars and other stuff i dont know>
这是什么意思?顺便说一句,我使用 JQuery 库..也许这就是问题所在^^..
I just tested my custom gallery script at JSLint.. and all errors where solved except for one.
The implied global error.. Is this really an error? Can I ignore it or should I work on it to solve this error..?
Thank you for your responses!
Error:
Implied global:
<bunch of vars and other stuff i dont know>
What does this mean? BTW I use JQuery Library.. maybe thats the problem^^..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您像本例一样使用外部声明的变量,请在文件顶部放置一个“global”语句,如下所示:
/*global $, document */
if you use externally declared variables like in this case, put a 'global' statement at the top of your file, like this:
/*global $, document */
JSLint 文档说:
请注意该错误。几乎每个编码约定都希望您不要使用隐含的全局变量。
可以使用
var
关键字声明变量。JSLint documentation says:
Care for that error. Nearly every coding convention wants you not to use implied globals.
Variables can be declared using the
var
keyword.当为浏览器编写 JavaScript 代码时,向 JSLint 表明您处于浏览器模式是很有用的,例如通过包含以下内容:
这应该解析 'document'、'setTimeout' 和其他典型的浏览器默认值,
因为 jQuery 可能不被使用在与 JavaScript 相同的上下文中进行评估,您需要让它知道有用的“$”可用于:
When writing JavaScript code for a browser, it is useful to indicate to JSLint that you are in browser mode, such as by including this:
This should resolve 'document', 'setTimeout', and other typical browser defaults
Since jQuery is probably not being evaluated in the same context as your JavaScript, you'll need to let it be known that the ever-useful '$' is available with: