开发者

I have ran JSLint tool on my java script files. I have fixed most of the issues, but I am not able to fix one comment

开发者 https://www.devze.com 2023-02-06 04:43 出处:网络
I have ran JSLint tool on my java script files. I have fixed most of the issues, but I am not able to fix one comment.

I have ran JSLint tool on my java script files. I have fixed most of the issues, but I am not able to fix one comment.

Implied global:

  • document 1,4,7,10,31,34,38,58,61,64,67,74,103,10开发者_如何学Go6,109,432,441,450,
  • confirm 364,
  • hideErrorMessageFields 403,
  • spanBusinessDivisionValidate 409,
  • spanBusinessGroupValidate 418,
  • validatePeoplePicker 425,434,452,
  • spanPeopleWorkingOSSValidate 427,
  • spanRequiredGMAliasValidate 436,

How to fix this comment?


You are referring to document, confirm etc. as things that exist in the global namespace.

JSLint doesn't magically know they are there. So you can use the global option to declare them as known globals by adding

/*global document confirm etc*/

To the top of your file. This needs to be a comment and countain a space seperated list of names, variables, functions, etc that you know to be global. Then JSLint will stop warning you that it doesn't know about them.


  JSLint documentation says: 

Undefined Variables and Functions

JavaScript's biggest problem is its dependence on global variables, particularly implied global variables. If a variable is not explicitly declared (usually with the var statement), then JavaScript assumes that the variable was global. This can mask misspelled names and other problems.

JSLint expects that all variables and functions are declared before they are used or invoked. This allows it to detect implied global variables. It is also good practice because it makes programs easier to read.

Care for that error. Nearly every coding convention wants you not to use implied globals. 

Variables can be declared using the var keyword


Add the 'Assume a Browser' flag to the top of your JS File:

/*jslint browser:true*/

From JSLint:

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. It has the same effect as this comment:

/*global addEventListener: false, blur: false, clearInterval: false, clearTimeout: false, close: false, closed: false, defaultStatus: false, document: false, event: false, focus: false, frames: false, getComputedStyle: false, history: false, Image: false, length: false, location: false, moveBy: false, moveTo: false, name: false, navigator: false, onblur: true, onerror: true, onfocus: true, onload: true, onresize: true, onunload: true, open: false, opener: false, Option: false, parent: false, print: false, resizeBy: false, resizeTo: false, screen: false, scroll: false, scrollBy: false, scrollTo: false, setInterval: false, setTimeout: false, status: false, top: false, XMLHttpRequest: false */

0

精彩评论

暂无评论...
验证码 换一张
取 消