如何更正“在定义文档之前就使用了文档".使用Jslint [英] How to rectify "Document was used before it was defined" using Jslint

查看:44
本文介绍了如何更正“在定义文档之前就使用了文档".使用Jslint的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 jsLint 中遇到以下错误:

文档"在定义之前就已使用.

'document' was used before it was defined.

导致错误的行:

document.cookie = name + "=" + value + expires + "; path=/";

我知道为什么会这样,但是我希望我的代码符合要求.

I get why this happens, but I would like my code to be compliant.

我该如何解决?

谢谢.

推荐答案

放置

/*jslint browser:true */

在函数正文的开头.或者,您也可以使用

in the beginning of the body of your function. Or, alternatively, you may use

/*global document: false */

JSLint用于检查任何javascript代码,并且document全局对象并不处处存在,因此您必须手动告诉JSLint您的代码旨在在浏览器中执行,因此document全局变量被定义为.例如,对于服务器端javascript,希望JSLint报告此错误.

JSLint is for the checking of any javascript code, and the document global object does not exists everywhere, so you have to manually tell JSLint that your code is aimed to be executed in browser, and thus document global variable is defined. For example, for server-side javascript it is expected for JSLint to report about this error.

这篇关于如何更正“在定义文档之前就使用了文档".使用Jslint的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆