JSHint Options 翻译
Enforcing options
When set to true, these options will make JSHint produce more warnings about your code.
This option prohibits the use of bitwise operators such as ^ (XOR), | (OR) and others. Bitwise operators are very rare in JavaScript programs and quite often & is simply a mistyped &&.
【此选项禁止使用位运算符比如^(异或),|(或)等。位运算符是非常罕见的JavaScript程序,并经常与仅仅是一个&& 和& 】
This option allows you to force all variable names to use either camelCase style or UPPER_CASE with underscores.
【此选项允许您强制所有变量名以使用驼峰式或UPPER_CASE带下划线。】
This option requires you to always put curly braces around blocks in loops and conditionals. JavaScript allows you to omit curly braces when the block consists of only one statement, for example:
while (day)
shuffle();
However, in some circumstances, it can lead to bugs (you'd think that sleep() is a part of the loop while in reality it is not):
while (day)
shuffle();
sleep();
【此选项要求你总是把大括号各地块的循环和条件。 JavaScript允许你省略花括号当块只包含一个语句】
This options prohibits the use of == and != in favor of === and !==. The former try to coerce values before comparing them which can lead to some unexpected results. The latter don't do any coercion so they are generally safer. If you would like to learn more about type coercion in JavaScript, we recommend Truth, Equality and JavaScript by Angus Croll.
【这个选项禁止使用==和!=赞成===和!==。前者试图比较它们可能导致一些意想不到的结果之前,强制值。后者没有做任何强迫因此它们通常更安全】
This option tells JSHint that your code needs to adhere to ECMAScript 3 specification. Use this option if you need your program to be executable in older browsers—such as Internet Explorer 6/7/8/9—and other legacy JavaScript environments.
【这个选项告诉JSHint你的代码需要遵循的ECMAScript3规范。如果你需要你的程序必须是可执行的在旧的浏览器,如Internet Explorer6/7/8/9-and其他传统的JavaScript环境中使用此选项。】
This option requires all for in loops to filter object's items. The for in statement allows for looping through the names of all of the properties of an object including those inherited throught the prototype chain. This behavior can lead to unexpected items in your object so it is generally safer to always filter inherited properties out as shown in the example:
for (key in obj) {
if (obj.hasOwnProperty(key)) {
// We are sure that obj[key] belongs to the object and was not inherited.
}
}
For more in-depth understanding of for in loops in JavaScript, read Exploring JavaScript for-in loops by Angus Croll.
【此选项要求所有为循环过滤对象的项目。在声明中对允许通过所有包括那些继承有着相同的原型链中的对象的属性的名称循环。这种行为可能会导致你的对象意想不到的项目,因此它通常是安全的】
This options prohibits overwriting prototypes of native objects such as Array, Date and so on.
/* jshint freeze:true */
Array.prototype.count = function (value) { return 4; };
// -> Warning: Extending prototype of native object: 'Array'.
【这个选项禁止覆盖原生的对象,如数组,日期等的原型。】
This option prohibits the use of immediate function invocations without wrapping them in parentheses. Wrapping parentheses assists readers of your code in understanding that the expression is the result of a function, and not the function itself.
【这个选项立即禁止使用函数调用没有包装在括号中。包装括号帮助读者理解你的代码的,表达式是一个函数的结果,而不是函数本身。
感觉是立即执行函数和函数表达式相关的】
This option enforces specific tab width for your code. For example, the following code will trigger a warning on line 4:
/*jshint indent:4 */
if (cond) {
doSomething(); // We used only two spaces for indentation here
}
【此选项强制特定的标签宽度为您的代码】
This option prohibits the use of a variable before it was defined. JavaScript has function scope only and, in addition to that, all variables are always moved—or hoisted— to the top of the function. This behavior can lead to some very nasty bugs and that's why it is safer to always use variable only after they have been explicitly defined.
Setting this option to "nofunc" will allow function declarations to be ignored.
For more in-depth understanding of scoping and hoisting in JavaScript, read JavaScript Scoping and Hoisting by Ben Cherry.
【
此选项禁止使用的变量定义它之前使用它。 JavaScript有函数作用域只,而在除此之外,所有的变量总是移动或悬挂到该函数的顶部。这种行为可能会导致一些非常讨厌的错误,这就是为什么它是安全的,他们已经被明确定义后,才总是使用变量。
将此选项设置为“nofunc”将允许函数声明被忽略。
为了更深入的了解范围界定及吊装在JavaScript中,读取JavaScript的作用域和由Ben樱桃吊装。
】
This option requires you to capitalize names of constructor functions. Capitalizing functions that are intended to be used with new operator is just a convention that helps programmers to visually distinguish constructor functions from other types of functions to help spot mistakes when using this.
Not doing so won't break your code in any browsers or environments but it will be a bit harder to figure out—by reading the code—if the function was supposed to be used with or without new. And this is important because when the function that was intended to be used with new is used without it, this will point to the global object instead of a new object.
【
此选项需要你大些的构造函数的名称。凭借此举的目的是要与新的运营商使用的功能仅仅是一个惯例,可以帮助程序员从视觉上分辨构造函数与其他类型的函数时使用它来帮助发现错误。
】
This option prohibits the use of arguments.caller and arguments.callee. Both.caller and .callee make quite a few optimizations impossible so they were deprecated in future versions of JavaScript. In fact, ECMAScript 5 forbids the use of arguments.callee in strict mode.
【此选项禁止使用arguments.caller和arguments.callee的的。两者都是。来电和。被叫做了不少优化,不可能让他们被抛弃在JavaScript的未来版本。事实上,ECMAScript 5标准不允许在严格模式下使用arguments.callee的。】
This option warns when you have an empty block in your code. JSLint was originally warning for all empty blocks and we simply made it optional. There were no studies reporting that empty blocks in JavaScript break your code in any way.
【此选项警告,当你有一个空的块中的代码。 JSLint的最初警告所有的空块,我们只是做了可选的】
This option warns about "non-breaking whitespace" characters. These characters can be entered with option-space on Mac computers and have a potential of breaking non-UTF8 web pages.
【此选项警告有关“非中断空格”字符。这些字符可以用在Mac电脑上的选项,空格中,并有打破非UTF8网页的潜力。】
This option prohibits the use of constructor functions for side-effects. Some people like to call constructor functions without assigning its result to any variable:
new MyConstructor();
There is no advantage in this approach over simply calling MyConstructor since the object that the operator new creates isn't used anywhere so you should generally avoid constructors like this one.
【禁止 空构造函数 此选项禁止使用构造函数的副作用。有些人喜欢调用构造函数,而不指定其结果的任何变量:】
This option prohibits the use of unary increment and decrement operators. Some people think that ++ and -- reduces the quality of their coding styles and there are programming languages—such as Python—that go completely without these operators.
【此选项禁止使用一元递增和递减运算符。有人认为,+ +和 - 减少了他们的编码风格的品质和有编程语言,如Python,那去完全没有这些运营商。】
This option enforces the consistency of quotation marks used throughout your code. It accepts three values: true if you don't want to enforce one particular style but want some consistency,"single" if you want to allow only single quotes and "double" if you want to allow only double quotes.
【这个选项强制在整个代码中使用引号的一致性。它接受三个值:true,如果你不希望强制一个特定的风格,但要一定的连贯性,“单”,如果你想只允许单引号和“双”,如果你想只允许双引号。】
This option prohibits the use of explicitly undeclared variables. This option is very useful for spotting leaking and mistyped variables.
/*jshint undef:true */
function test() {
var myVar = 'Hello, World';
console.log(myvar); // Oops, typoed here. JSHint with undef will complain
}
If your variable is defined in another file, you can use /*global ... */ directive to tell JSHint about it.
【此选项禁止使用未显示声明的变量。此选项为察觉漏水和拼写错误的变量非常有用。】
This option warns when you define and never use your variables. It is very useful for general code cleanup, especially when used in addition to undef.
/*jshint unused:true */
function test(a, b) {
var c, d = 2;
return a + d;
}
test(1, 2);
// Line 3: 'b' was defined but never used.
// Line 4: 'c' was defined but never used.
In addition to that, this option will warn you about unused global variables declared via/*global ... */ directive.
This can be set to vars to only check for variables, not function parameters, or strict to check all variables and parameters. The default (true) behavior is to allow unused parameters that are followed by a used parameter.
【此选项警告,当你定义和从不使用的变量。它是用于一般的代码清理非常有用的】
This option requires all functions to run in ECMAScript 5's strict mode. Strict mode is a way to opt in to a restricted variant of JavaScript. Strict mode eliminates some JavaScript pitfalls that didn't cause errors by changing them to produce errors. It also fixes mistakes that made it difficult for the JavaScript engines to perform certain optimizations.
Note: This option enables strict mode for function scope only. It prohibits the global scoped strict mode because it might break third-party widgets on your page. If you really want to use global strict mode, see the globalstrict option.
【
此选项需要的所有功能,ECMAScript 5中的严格模式下运行。严格模式是一种选择加入JavaScript的一个变种限制。严格模式消除了一些JavaScript的缺陷是没有改变他们产生错误导致错误。它还修正错误,使得它难以对JavaScript引擎来执行某些优化。
注意:这个选项开启严格模式唯一的功能范围。它禁止在全球范围的严格模式,因为它可能会破坏第三方小部件您的网页上。如果你真的想使用全局严格模式,请参阅globalstrict选项。
】
This option makes it an error to leave a trailing whitespace in your code. Trailing whitespaces can be source of nasty bugs with multi-line strings in JavaScript:
// This otherwise perfectly valid string will error if
// there is a whitespace after \
var str = "Hello \
World";
【通过该选项,错误的留在你的代码中的尾随空格。尾部空格可以是讨厌的错误在JavaScript中使用多行字符串来源:】
This option lets you set the max number of formal parameters allowed per function:
/*jshint maxparams:3 */
function login(request, onSuccess) {
// ...
}
// JSHint: Too many parameters per function (4).
function logout(request, isManual, whereAmI, onSuccess) {
// ...
}
【此选项允许您设置的每个函数允许的形式参数的最大数量】
This option lets you control how nested do you want your blocks to be:
/*jshint maxdepth:2 */
function main(meaning) {
var day = true;
if (meaning === 42) {
while (day) {
shuffle();
if (tired) { // JSHint: Blocks are nested too deeply (3).
sleep();
}
}
}
}
【此选项可让您控制如何嵌套的数量,你希望你的模块是:】
This option lets you set the max number of statements allowed per function:
/*jshint maxstatements:4 */
function main() {
var i = 0;
var j = 0;
// Function declarations count as one statement. Their bodies
// don't get taken into account for the outer function.
function inner() {
var i2 = 1;
var j2 = 1;
return i2 + j2;
}
j = i + j;
return j; // JSHint: Too many statements per function. (5)
}
【此选项允许您设置每个功能允许报表的最大数量:】
This option lets you control cyclomatic complexity throughout your code. Cyclomatic complexity measures the number of linearly independent paths through a program's source code. Read more about cyclomatic complexity on Wikipedia.
【这是什么意思 控制复杂度的?
此选项可让您在整个代码控制圈复杂度。圈复杂度通过一个程序的源代码测量线性独立路径数。了解更多关于圈维基百科上的复杂性。】
This option lets you set the maximum length of a line.
【此选项允许您设置行的最大长度】
Environments
These options let JSHint know about some pre-defined global variables.
This option defines globals exposed by modern browsers: all the way from good old document andnavigator to the HTML5 FileReader and other new developments in the browser world.
【支持代码运行的在浏览器上,包含相关的api】
Note: This option doesn't expose variables like alert or console. See option devel for more information.
This option defines globals exposed by CouchDB. CouchDB is a document-oriented database that can be queried and indexed in a MapReduce fashion using JavaScript.
【此选项定义了CouchDB的暴露全局。 CouchDB是可以查询的,并在使用JavaScript MapReduce的方式进行索引的面向文档的数据库。】
This option defines globals that are usually used for logging poor-man's debugging: console,alert, etc. It is usually a good idea to not ship them in production because, for example,console.log breaks in legacy versions of Internet Explorer.
【开发和调试用到的api,此选项定义全局变量,通常是用于登录穷人的调试:控制台,提醒等,这通常是一个好主意,不发货他们在生产,因为,例如,在Internet Explorer中的旧版本的console.log休息。】
This option defines globals exposed by the Dojo Toolkit.
This option defines globals exposed by the jQuery JavaScript library.
This option defines globals exposed by the MooTools JavaScript framework.
This option defines globals available when your code is running inside of the Node runtime environment. Node.js is a server-side JavaScript environment that uses an asynchronous event-driven model. This option also skips some warnings that make sense in the browser environments but don't make sense in Node such as file-level use strict pragmas and console.logstatements.
This option defines non-standard but widely adopted globals such as escape and unescape.
This option defines globals available when your core is running inside of the PhantomJS runtime environment. PhantomJS is a headless WebKit scriptable with a JavaScript API. It has fast and native support for various web standards: DOM handling, CSS selector, JSON, Canvas, and SVG.
This option defines globals exposed by the Prototype JavaScript framework.
This option defines globals available when your code is running inside of the Rhino runtime environment. Rhino is an open-source implementation of JavaScript written entirely in Java.
This option defines globals available when your code is running inside of a Web Worker. Web Workers provide a simple means for web content to run scripts in background threads.
This option defines globals available when your code is running as a script for the Windows Script Host.
This option defines globals exposed by the YUI JavaScript framework.
JSHint Options 翻译的更多相关文章
- jshint options
jshint -W032 忽略if代码块后有多余的分号的提示 地址:jslinterrors.com/unnecessary-semicolon asi 忽略函数定义后必须加分号的提示 c ...
- 在Eclipse中使用JSHint检查JavaScript
之前使用 JSlint 来校验 JavaScript 代码,发现灵活性不够,因此改用 JSHint.按照官方的说法,JSHint 是一个社区驱动(community-driven)的工具,用于检测Ja ...
- Grunt 之 使用 JavaScript 语法检查工具 jshint
前端开发环境准备好了,我们准备开始进行开发. 前端开发的主力语言是 JavaScript,这是一种脚本语言,没有编译器,也就没有了编译器带给我们的语法检查,怎样保证代码的质量呢?jshint 是一个强 ...
- 在 Eclipse 中使用 JSHint 检查 JavaScript 代码
JSHint Home: http://www.jshint.com/ JSHint Options: http://www.jshint.com/options/ JSHint For Eclips ...
- .NET Core 2.x中使用Named Options处理多个强类型配置实例
来源: Using multiple instances of strongly-typed settings with named options in .NET Core 2.x 作者: Andr ...
- Grunt jshint Warning: Path must be a string . Received null Use
用grunt监视文件,出现'Warning: Path must be a string . Received null Use --force to continue 原因是没有设置reporter ...
- 百度翻译api 实现简易微信翻译小程序
介绍 口袋翻译 口袋翻译 微信小程序 翻译功能 含7类语言的相互翻译 包含最近10条的翻译历史回溯功能 微信搜索:简e翻译 功能展示 使用百度翻译api需要申请 appid 与 key 并在 ap ...
- 解决incorrect 'only available in ES6' warning (W119) with options `moz: true, esversion: 6` 报错问题
很多同学在新建vue项目时,会遇到 incorrect 'only available in ES6' warning (W119) with options `moz: true, esversio ...
- 用grunt搭建自动化的web前端开发环境实战教程(详细步骤)
用grunt搭建自动化的web前端开发环境实战教程(详细步骤) jQuery在使用grunt,bootstrap在使用grunt,百度UEditor在使用grunt,你没有理由不学.不用!前端自动化, ...
随机推荐
- Mac 效率工具
我的Mac开发环境 http://blog.csdn.net/feelang/article/details/45071249 iterm2 http://iterm2.com/documentati ...
- [NHibernate]立即加载
目录 写在前面 文档与系列文章 立即加载 一个例子 总结 写在前面 上篇文章介绍了nhibernate延迟加载的相关内容,简单回顾一下延迟加载,就是需要的时候再去加载,需要的时候再向数据库发出sql指 ...
- jenkins使用简记
一.安装 jenkins有多种安装方式,可以使用内嵌的Servlet容器运行,也可以基于Apache运行,也可以安装成Linux或Windows服务. 1.使用 Servlet 容器运行 从官网下载 ...
- Android 网络编程
HttpClient 发送get请求 创建一个客户端对象 HttpClient client = new DefaultHttpClient(); 创建一个get请求对象 HttpGet hg = n ...
- mysql安装配置
MySQL 是最流行的关系型数据库管理系统,由瑞典MySQL AB公司开发,目前属于Oracle公司. MySQL所使用的SQL语言是用于访问数据库的最常用标准化语言. MySQL由于其体积小.速度快 ...
- 如何自定义iphone个性铃音
准备工作:itunes.(Netease Cloud Music).iphone 1.下载你想要的铃音原音乐: 2.打开itunes,向音乐库中添加刚刚下载的音乐: "文件"-&g ...
- 清北学堂模拟赛day7 数字碰撞
/* clj:水题别人都满分你不是你就完了,所以说水题一定要细心一点,有这么几个细节:①前导零的处理,全是零的时候要特判②换行要注意,不要多大一行,剩下就是水水的模拟了 */ #include< ...
- cpu对各种运算的速度对比
今天忽然想到cpu对各种基本运算的速度对比,我对比了异或,加法和乘法,结果发现速度时间,加法小于乘法小于异或, 原本我以为异或会是最快的,结果异或是最慢的,这跟cpu中的alu算术逻辑单元的实现有关, ...
- 微信安卓版下载 Android微信各版本列表
前面ytkah弄了一个iso微信各版本列表,现在就来整一个微信 for Android各版本列表,方便大伙下载.每个版本都放出一些新的功能或修复相关错误,详情可以点击下面的版本链接进行查看.资源收集于 ...
- 如何 实现PHP多版本的 共存 和 切换?
编译PHP时指定路径 ./configure --prefix=/opt/php/php-5.6 make && make install 这样可以PHP版本就可以安装到一个特别的路径 ...