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

函数调用时,参数与左右括号之间是否应该有空格? #4

Open
2betop opened this issue Apr 23, 2014 · 4 comments
Open

Comments

@2betop
Copy link
Contributor

2betop commented Apr 23, 2014

我比较喜欢调用的时候参数与左右括号之间带空格,但是在以下几种case的时候没有空格。之前很多人都觉得这些规则太复杂,不知道大家怎么看。

// 2.C.1.1
// Functions with callbacks
foo(function() {
  // Note there is no extra space between the first paren
  // of the executing function call and the word "function"
});

// Function accepting an array, no space
foo([ "alpha", "beta" ]);

// 2.C.1.2
// Function accepting an object, no space
foo({
  a: "alpha",
  b: "beta"
});

// Single argument string literal, no space
foo("bar");

// Inner grouping parens, no space
if ( !("foo" in obj) ) {

}
@2betop
Copy link
Contributor Author

2betop commented Apr 23, 2014

以上内容源于此:https://github.com/rwaldron/idiomatic.js

@Singularity-zju
Copy link
Contributor

我参数和左右括号直接一般不加空格,参数之间用空格隔开。
foo(x, y);

@2betop
Copy link
Contributor Author

2betop commented Apr 23, 2014

但是感觉有点空格还是要看点,像jquery就是固定两边有空格,没有Exceptions

@nwind
Copy link
Member

nwind commented Apr 24, 2014

无空格+1,有空格看起来有点奇怪。
学芝在遇到类似这种不明确时,可以考虑参考其它类 C 语言的规范,比如 PHP、Java、C++,因为大家有时需要阅读其它代码,如果能尽量兼容最好。

@miller miller modified the milestones: pre alpha, 1st edition Apr 25, 2014
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