新线上的JavaScript花括号? [英] JavaScript braces on new line or not?

查看:201
本文介绍了新线上的JavaScript花括号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在工作中,我们把大括号放在下一行,但在家里,我做的相反。你更倾向哪个? (K& R vs OTBS)

At work, we place braces on the next line, but at home, I do the opposite. Which one do you prefer? (K&R vs OTBS)

function something() {
    // ...
}

function something()
{
    // ...
}

很多JavaScript库似乎使用OTBS(一种真正的大括号风格)。我想跟踪他们在其他JavaScript项目之间的一致性,但不是K& R风格看起来更容易阅读?

A lot of JavaScript libraries seem to use the OTBS (one true brace style). I'd like to follow them for consistence among other JavaScript projects, but doesn't K&R style look more readable?

注意:我们知道return的问题,在JavaScript中的大括号,这将永远是一个例外。

Note: We know the problem with return and braces in JavaScript, that will always be an exception. However, that is only a single case.

推荐答案

这是一个神圣的战争,你永远不会得到一个有用的答案!只要坚持项目中的每个人都在使用,不要争论!

This is a Holy War to which you will never get a usable answer! Just stick with whatever everyone else in the project is using and don't argue!

对于值得的,我是一个K& Rite。我发现OTBS在开放式结构和下面的语句之间放置了很多可视化空间,当这两行经常强烈相关时,将更好地呈现在一起,而没有中间的几乎空白的行。我喜欢保留我的空白行保留用于分隔相关语句的块。

For what it's worth, I'm a K&Rite. I find the OTBS puts a lot of visual space between an opening structure and the following statement, when those two lines are often strongly related so would be better presented together, without an intervening almost-blank line. I like to keep my blank lines reserved for separating blocks of related statements.

在很多空白的编码风格中,这可能是相对不重要的。但我个人认为我的简洁,所以我可以保留更多的程序在屏幕上。

In a coding style which a lot of whitespace anyway, this may be relatively unimportant. But personally I value terseness, so I can keep more of the program on-screen.

我不买那个有开放支架在不同的列到关闭支架是一个问题。它仍然很容易看到块形状只是从缩进。除非你使用悬挂缩进。不要这样做。但这完全是另一个圣战。

I don't buy that having the open-brace on a different column to the close-brace is an issue. It's still easy to see the block shape just from the indents. Unless you're using hanging indents. Don't do that. But that's another Holy War entirely.

这篇关于新线上的JavaScript花括号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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