JSLint,else和预期'}'和'else'错误之间只有一个空格 [英] JSLint, else and Expected exactly one space between '}' and 'else' error

查看:182
本文介绍了JSLint,else和预期'}'和'else'错误之间只有一个空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么 JSLint 报告代码:

 函数cos(a){
var b = 0;
如果(a){
b = 1;
}
else {
b = 2;
}

返回b;
}

错误:

 第6行问题5:预计'}'和'else'之间只有一个空格。 

可以通过禁用 Tolerate messy white space 选项来关闭此错误JSLint。



或换句话说 - 为什么语法:
}否则{优于

  ... 
}
else {
...

Google还使用语法与}否则{表单。



<但是我不明白为什么。 Google提到了隐式分号插入,但是在打开 {,而不是关闭一个。



Can的情况下Javascript在关闭}后插入分号如果阻止,即使下一个令牌是 else 指示?



抱歉我的问题有点混乱 - 我试图大声思考

解决方案

JSLint基于Crockford的偏好(我在这种情况下分享)。



它是是一个更好的意见问题。



(虽然显然他的观点是对的;)


Why JSLint report in code:

function cos(a) {
    var b = 0;
    if (a) {
        b = 1;
    }
    else {
        b = 2;
    }

    return b;
}

error:

Problem at line 6 character 5: Expected exactly one space between '}' and 'else'.

This error can be turned off by disabling Tolerate messy white space option of JSLint.

Or in other words -- why syntax: } else { is better then

...
}
else {
...

Google also uses syntax with } else { form.

But I don't understand why. Google mentioned ''implicit semicolon insertion'', but in context of opening {, not closing one.

Can Javascript insert semicolon after closing } of if block even if next token is else instruction?

Sorry that my question is a bit chaotic -- I tried to think loud.

解决方案

JSLint is based on Crockford's preferences (which I share in this case).

It's a matter of opinion which is "better".

(Although clearly his opinion is right ;)

这篇关于JSLint,else和预期'}'和'else'错误之间只有一个空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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