Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if, for等强制{}会不会更好点 #9

Open
oxUnd opened this issue Apr 28, 2014 · 6 comments
Open

if, for等强制{}会不会更好点 #9

oxUnd opened this issue Apr 28, 2014 · 6 comments
Assignees
Milestone

Comments

@oxUnd
Copy link
Contributor

oxUnd commented Apr 28, 2014

https://github.com/fex-team/styleguide/blob/master/javascript.md#%E5%9D%97%E7%8A%B6%E4%BB%A3%E7%A0%81

@Singularity-zju
Copy link
Contributor

必须顶 if的强制大括号,不然以后加个逻辑很容易忽略。
而且现在我记得Sublime这种编辑器里你直接if后面回车就自动加上大括号了。

@2betop
Copy link
Contributor

2betop commented Apr 28, 2014

+1

@miller miller added this to the 1st edition milestone Apr 28, 2014
@miller
Copy link
Contributor

miller commented Apr 28, 2014

+1 原来GMU貌似是强制的

@2betop
Copy link
Contributor

2betop commented Apr 28, 2014

想起来了,主要是考虑到这个case,独立一行可读性更强。

var noop = function() {};
var emptyObject = {};

@techird
Copy link
Member

techird commented Apr 30, 2014

很多时候我条件判断的时候只做一件事,我觉得还是不要强制的好。我建议如果 if / for 的执行只有一条语句的话,不写大括号需要强制写在一行,如果是多行,强制加大括号。

// good
if (isIE) doForIE();

// bad
if (isIE)
    doForIE();

// good
if (isIE) {
    doForIE();
}

// good
if (isIE) {
   doForIE();
   maskChrome();
}

@2betop
Copy link
Contributor

2betop commented Apr 30, 2014

如果只有一行我也倾向于 if (isIE) doForIE();这种写法,超过多行才强制用大括号。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants