问题描述
根据JSHint的说法,javascript程序员不应该在第一个括号之后和最后一个括号之前添加空格。
我确实看到很多好的javascript库使用这样的空间:
According to JSHint a javascript programmer should not use to add space after the first bracket and before the last one.I did see a lot of good javascript library which use space like this:
第一种方式(更多空格):
first way (more spaces):
( foo === bar ) // bad way according JSHint
而不是第二种方式:
(foo === bar) // good way for JSHint
坦率地说,我更喜欢第一种方式,更多空格,因为它使代码更具可读性。
Frankly, I prefer the first way, more spaces, because it makes the code more readable.
是否有理由更喜欢JSHint推荐的第二种方式?
Is there a strong reason to prefer the second way which is recommended by JSHint?
推荐答案
几乎没有技术理由更喜欢其中一个 - 原因几乎完全主观。
There are few if any technical reasons to prefer one over the other - the reasons are almost entirely subjective.
在我的情况下,我会使用第二种格式,因为:
In my case I would use the second format, simply because:
-
它完全可读,并且遵循广阔的Javascript的祖先语言中的大多数格式约定
It's perfectly readable, and follows the vast majority of formatting conventions in Javascript's ancestor languages
JS文件下载大小很重要[虽然缩小当然会解决这个问题]
JS file download size matters [although minification does of course fix that]
我一直这样做。
这篇关于Javascript中的编码约定:在括号之间使用空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!