MozillaFoundation / engineering-handbook

Mozilla Foundation's Engineering Handbook
https://mozillafoundation.github.io/engineering-handbook/
13 stars 11 forks source link

Write a Chapter: "Our JavaScript Style Guide" #13

Closed simonwex closed 3 years ago

simonwex commented 9 years ago

Airbnb JavaScript Style Guide() {

A mostly reasonable approach to JavaScript

Table of Contents

  1. Types
  2. undefined
  3. Objects
  4. Arrays
  5. Strings
  6. Functions
  7. Properties
  8. Variables
  9. Hoisting
  10. Conditional Expressions & Equality
  11. Blocks
  12. Comments
  13. Whitespace
  14. Commas
  15. Semicolons
  16. Type Casting & Coercion
  17. Naming Conventions
  18. Accessors
  19. Constructors
  20. Events
  21. Modules
  22. jQuery
  23. ECMAScript 5 Compatibility
  24. Testing
  25. Performance
  26. Resources
  27. In the Wild
  28. Translation
  29. The JavaScript Style Guide Guide
  30. Contributors
  31. License

    Types

    • Primitives: When you access a primitive type you work directly on its value
    • string
    • number
    • boolean
    • null
    • undefined
    var foo = 1;
    var bar = foo;
    
    bar = 9;
    
    console.log(foo, bar); // => 1, 9
    • Complex: When you access a complex type you work on a reference to its value
    • object
    • array
    • function
    var foo = [1, 2];
    var bar = foo;
    
    bar[0] = 9;
    
    console.log(foo[0], bar[0]); // => 9, 9

⬆ back to top

undefined

⬆ back to top

Objects

⬆ back to top

Objects

⬆ back to top

Arrays

⬆ back to top

Strings

⬆ back to top

Functions

⬆ back to top

Properties

⬆ back to top

Variables

⬆ back to top

Hoisting

⬆ back to top

Conditional Expressions & Equality

⬆ back to top

Blocks

⬆ back to top

Comments

⬆ back to top

Whitespace

⬆ back to top

Commas

⬆ back to top

Semicolons

⬆ back to top

Type Casting & Coercion

⬆ back to top

Naming Conventions

⬆ back to top

Accessors

⬆ back to top

Constructors

⬆ back to top

Events

⬆ back to top

jQuery

⬆ back to top

ECMAScript 5 Compatibility

⬆ back to top

Testing

⬆ back to top

Performance

⬆ back to top

Resources

Read This

Other Styleguides

Other Styles

Further Reading

Books

Blogs

⬆ back to top

In the Wild

This is a list of organizations that are using this style guide. Send us a pull request or open an issue and we'll add you to the list.

(The MIT License)

Copyright (c) 2014 Airbnb

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

⬆ back to top

};

davidascher commented 9 years ago

FYI: http://flowtype.org/docs/about-flow.html

simonwex commented 9 years ago

I think Andrew mentioned that. I dig the idea.

thisandagain commented 9 years ago

I'm in general a big fan of strict style checkers and static analysis. The one thing that I'd like to see even more than the style guide document is a set of JSCS / JSHINT config files that enforce them.

gvn commented 9 years ago

@thisandagain We'll be doing that in Unicorn. :+1:

See:

https://github.com/MozillaFoundation/unicorn/commit/15866a8e303f12f8dfecd7bb995448aac00f4baa

gvn commented 9 years ago

Also, we'll be enforcing via Travis.

See: https://gist.github.com/gvn/7536832

thisandagain commented 9 years ago

Great on both. Thanks @gvn