Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upWhy does this suggest Space after function name? #217
Comments
This comment has been minimized.
This comment has been minimized.
mattdesl
commented
Aug 2, 2015
|
See #89 |
This comment has been minimized.
This comment has been minimized.
|
Thanks, I couldn't find that earlier, probably because I was searching with the example given, and there was none in the referred issue. |
This comment has been minimized.
This comment has been minimized.
mattdesl
commented
Aug 2, 2015
|
I also found it weird when I started with |
This comment has been minimized.
This comment has been minimized.
|
I also found it weird in the beginning until I started writing ES2015 classes. Consider: class Widget {
doSomething () {
console.log('hi')
}
}vs class Widget {
doSomething() {
console.log('hi')
}
}So a case could be made that the space makes it 100% clear that it's a function declaration vs a function call. If you stick with Standard, I'd be willing to bet that after awhile, you won't mind that space. |
This comment has been minimized.
This comment has been minimized.
|
Well, currently I have mixed feeling about this. I still (have to) write mostly ES5 code and only two kinds of functions used are anonymous and named. Our rule, although not set by any linter, is to have a space before anonymous function's arguments, but not before the named one's. And that's not the only rule not compliant with Standard's one, so I don't see myself using it in my job anytime soon, but I will try to include it wherever I can and see how it works for me. |
This comment has been minimized.
This comment has been minimized.
|
@markogresak It sounds like |
This comment has been minimized.
This comment has been minimized.
mikeaustin
commented
Feb 17, 2018
|
I realize this question is old and we can just use eslint, but I still wanted to comment for completeness. Every other rule feels “standard” except this one. I think that’s why people, including me, are curious. When you call a function, you don’t add a space before the parenthesis. It looks asymmetrical compared to almost any other language, besides maybe Dylan. It is common to use a space when using legacy anonymous functions:
|
markogresak commentedAug 2, 2015
Why should we write named functions as
function name (arg) { ... }? I tried to search the issues, but couldn't find any explanation.From other C-like languages, the function name and arguments list are always adjacent, without any space in-between, but there should be a space before anonymous function arguments list.
Also nicely explained in Crockford on JavaScript - Section 8: Programming Style & Your Brain (at 32:29).