Open kahnvex opened 9 years ago
The airbnb style guide is pretty good, there is a lot of overlap, such as:
13.2 Use one const declaration per variable. eslint: one-var jscs: disallowMultipleVarDecl Why? It's easier to add new variable declarations this way, and you never have to worry about swapping out a ; for a , or introducing punctuation-only diffs. You can also step through each declaration with the debugger, instead of jumping through all of them at once.
I found one glaring disagreement and they provide compelling reason:
7.1 Use function declarations instead of function expressions. jscs: requireFunctionDeclarations
Why? Function declarations are named, so they're easier to identify in call stacks. Also, the whole body of a function declaration is hoisted, whereas only the reference of a function expression is hoisted. This rule makes it possible to always use Arrow Functions in place of function expressions.
Maybe it is time to ditch Google's style guide?
I didn't realize that named functions are used in call stacks. That alone would be enough for me to start using function declarations.
Interesting footnote concerning ES6 semantics: https://github.com/airbnb/javascript/issues/794
Also, when compiling to es5, babel ensures a named function is used:
const foo = () => "foo";
becomes
var foo = function foo() {
return "foo";
};
We should update the style guide to take into consideration ES6 best practices. There are new language level features that should be taken into consideration here: