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

对短路写法怎么看 #12

Open
hefangshi opened this issue Apr 30, 2014 · 4 comments
Open

对短路写法怎么看 #12

hefangshi opened this issue Apr 30, 2014 · 4 comments

Comments

@hefangshi
Copy link
Member

类似

callback && callback();

options = options || {};

甚至混杂一些赋值

someCondition && (a = 1);

这些写法呢?个人觉得上面的写法还是比较方便的,但是下面是不是属于滥用了?

@2betop
Copy link
Contributor

2betop commented Apr 30, 2014

我也比较倾向于这种写法!

@techird
Copy link
Member

techird commented May 2, 2014

不支持短路,觉得如果确实是个分支语句就写 if 好了,清晰一些。压缩工具也会自动转成短路语句。

@hefangshi
Copy link
Member Author

@techird 简短的语法不仅可以提高编码速度,也能提高代码可读性,比如有多个地方会用到callback调用,如果每次都写一个if (callback) {callback()},不仅累赘,代码长度也会增加不少

@Singularity-zju
Copy link
Contributor

简单的短路无妨,不要超出一个表达式或者嵌套好几层逻辑就好

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

4 participants