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

Update README to include ES6 Practices #21

Open
kahnvex opened this issue Sep 10, 2015 · 3 comments
Open

Update README to include ES6 Practices #21

kahnvex opened this issue Sep 10, 2015 · 3 comments
Labels

Comments

@kahnvex
Copy link
Contributor

kahnvex commented Sep 10, 2015

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:

  • Arrow functions
  • Descructuring
  • Rest params
  • Generators
  • Class definitions
@beck
Copy link
Contributor

beck commented May 31, 2016

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?

@kahnvex
Copy link
Contributor Author

kahnvex commented May 31, 2016

I didn't realize that named functions are used in call stacks. That alone would be enough for me to start using function declarations.

@beck
Copy link
Contributor

beck commented May 31, 2016

Interesting footnote concerning ES6 semantics:
airbnb/javascript#794

Also, when compiling to es5, babel ensures a named function is used:

const foo = () => "foo";

becomes

var foo = function foo() {
  return "foo";
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants