预期';'而是看到','。 - JSLint多变量设置 [英] Expected ';' and instead saw ','. - JSLint multivar setting

查看:95
本文介绍了预期';'而是看到','。 - JSLint多变量设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

截至2016年1月14日,JSLint已开始抱怨 var 声明有多个每个声明变量,并创建了一个新的指令, multivar 忽略了这个新的问题。

As of about 14 January 2016, JSLint has started complaining about var or let declarations that have more than one variable per declaration, and has created a new directive, multivar that ignores this new "problem".

这是一个非常重要的变化,因为如果 在同一代码块中有两个 var s,早期版本会抱怨。

This is a pretty significant change, as earlier versions would complain if you did have two vars in the same code block.

即截至今天(2016年1月18日),此代码现已在 JSLint 中断:

That is, as of today (18 Jan 2016), this code now breaks in JSLint:

/*jslint white:true, browser:true, devel:true */
function a(b) {
    "use strict";
    var c, d; // <<< Now bad!!
    d = "test";
    c = d + b;
    console.log(c);
}

报告的错误是,预期';'和而是看到','。为行 var c,d;

正确修复显然是这样的:

The "correct" fix is apparently this:

/*jslint white:true, browser:true, devel:true */
function a(b) {
    "use strict";
    var c;
    var d;  // <<< this *used* to be forbidden.
    d = "test";
    c = d + b;
    console.log(c);
}

请注意,这个新的正确代码会产生错误,错误:combine_var ,在早期版本的JSLint 中。

Note that this newly correct code would have produced the error, Error: combine_var, in earlier versions of JSLint.

我能找到的Crockford变更的唯一描述似乎是 Google Plus上的这篇文章

The only descriptions for the change from Crockford that I can find seem to be this post on Google Plus:


JSLint现在有一个 multivar 允许在单个var,let或const语句中声明多个名称的选项。

JSLint now has a multivar option that tolerates multiple names being declared in a single var, let, or const statement.

...快速提及网站说明 ...

... and a quick mention on the website instructions...


容忍每个语句的多个变量声明

multivar

true 如果 var ,或 const 声明可以de在单个语句中克制两个或多个变量。

Tolerate multiple variables declarations per statement
multivar
true if a var, let, or const statement can declare two or more variables in a single statement.

多变量更改为JSLint.com似乎还不在GitHub回购中。请参阅两个签到( 1 2 )1月14日标题为var。这两个使得JSLint中的代码遵循新的要求,但不要(afaict)添加在JSLint.com上描述和使用的 multivar 指令。

The multivar change on JSLint.com doesn't seem to be in the GitHub repo yet. See the two checkins (1, 2) entitled "var" for 14 Jan. Those two make the code in JSLint follow the new requirement, but don't (afaict) add the multivar directive described and in use on JSLint.com.

任何人都可以告诉我为什么多个 var 现在鼓励/需要行,除了通常的你应该忽略JSLint,答案?也就是说,为什么在之前需要单个变量(我猜想鼓励理解提升),为什么这个推理突然没有用?

Can anybody tell me why multiple var lines are encouraged/required now, other than the usual, "You should ignore JSLint," answers? That is, why was a single var required before (I'd guess to encourage an understanding of hoisting), and why is that reasoning suddenly moot?

推荐答案

来自AirBNB风格指南。

From the AirBNB style guide.


以这种方式添加新的变量声明更容易,你永远不必担心交换a;用于a,或引入仅用于标点符号的差异。您也可以使用调试器逐步完成每个声明,而不是一次跳过所有声明。

It's easier to add new variable declarations this way, and you never have to worry about swapping out a ; for a , or introducing punctuation-only diffs. You can also step through each declaration with the debugger, instead of jumping through all of them at once.

更多相关内容:< a href =https://github.com/airbnb/javascript#variables =nofollow> https://github.com/airbnb/javascript#variables

这篇关于预期';'而是看到','。 - JSLint多变量设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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