本文介绍了JSLint:在定义之前使用过的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 您好我有3个javascript文件。Hi I have the 3 javascript files. jquery.js utility.js file1.js在file1.js中我有In file1.js I havejQuery.noConflict()jQuery(document).ready(function($) { // ....});我收到错误'jQuery'在定义之前使用过。 和'document'在定义之前使用。I get an error 'jQuery' was used before it was defined.and 'document' was used before it was defined.如何安全地摆脱此警告。How do I safely get rid of this warning.如果我这样做var document = document || {};然后在我的utility.js中如果使用它,它在IE中将为null并且在Firefox中为ok 。then in my utility.js if it is used, it would be null in IE and ok in firefox.最佳解决方案是什么?推荐答案来自文档 JSLint还识别一个/ * global * /指令,该指令可以向JSLint指示此文件中使用的变量是在其他文件中定义的。注释可以包含逗号分隔的名称列表。每个名称可以后跟一个冒号,后跟true或false,true表示该变量可以由该文件赋值,false表示不允许赋值(默认值)。该指令尊重函数范围。 JSLint also recognizes a /*global */ directive that can indicate to JSLint that variables used in this file were defined in other files. The comment can contain a comma separated list of names. Each name can optionally be followed by a colon and either true or false, true indicating that the variable may be assigned to by this file, and false indicating that assignment is not allowed (which is the default). The directive respects function scope.可以为您预定义一些全局变量。选择假定浏览器(浏览器)选项以预定义Web浏览器提供的标准全局属性,例如document和addEventListener。Some globals can be predefined for you. Select the Assume a browser (browser) option to predefine the standard global properties that are supplied by web browsers, such as document and addEventListener.示例:/*jslint browser: true*//*global $, jQuery*/ 这篇关于JSLint:在定义之前使用过的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-12 01:02