javascript README

项目的 README,来自 github.com/airbnb/javascript。合并为一个 markdown 文件:README.md。

Airbnb JavaScript Style Guide() {

A mostly reasonable approach to JavaScript

Note: this guide assumes you are using Babel, and requires that you use babel-preset-airbnb or the equivalent. It also assumes you are installing shims/polyfills in your app, with airbnb-browser-shims or the equivalent.

Downloads Downloads Gitter

This guide is available in other languages too. See Translation

Other Style Guides

Table of Contents

  1. Types
  2. References
  3. Objects
  4. Arrays
  5. Destructuring
  6. Strings
  7. Functions
  8. Arrow Functions
  9. Classes & Constructors
  10. Modules
  11. Iterators and Generators
  12. Properties
  13. Variables
  14. Hoisting
  15. Comparison Operators & Equality
  16. Blocks
  17. Control Statements
  18. Comments
  19. Whitespace
  20. Commas
  21. Semicolons
  22. Type Casting & Coercion
  23. Naming Conventions
  24. Accessors
  25. Events
  26. jQuery
  27. ECMAScript 5 Compatibility
  28. ECMAScript 6+ (ES 2015+) Styles
  29. Standard Library
  30. Testing
  31. Performance
  32. Resources
  33. In the Wild
  34. Translation
  35. The JavaScript Style Guide Guide
  36. Chat With Us About JavaScript
  37. Contributors
  38. License
  39. Amendments

Types

⬆ back to top

References

⬆ back to top

Objects

⬆ back to top

Arrays

⬆ back to top

Destructuring

⬆ back to top

Strings

⬆ back to top

Functions

⬆ back to top

Arrow Functions

⬆ back to top

Classes & Constructors

⬆ back to top

Modules

⬆ back to top

Iterators and Generators

⬆ back to top

Properties

⬆ back to top

Variables

⬆ back to top

Hoisting

⬆ back to top

Comparison Operators & Equality

⬆ back to top

Blocks

⬆ back to top

Control Statements

⬆ 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

Events

⬆ back to top

jQuery

⬆ back to top

ECMAScript 5 Compatibility

⬆ back to top

ECMAScript 6+ (ES 2015+) Styles

  1. Arrow Functions
  2. Classes
  3. Object Shorthand
  4. Object Concise
  5. Object Computed Properties
  6. Template Strings
  7. Destructuring
  8. Default Parameters
  9. Rest
  10. Array Spreads
  11. Let and Const
  12. Exponentiation Operator
  13. Iterators and Generators
  14. Modules

⬆ back to top

Standard Library

The Standard Library contains utilities that are functionally broken but remain for legacy reasons.

⬆ back to top

Testing

⬆ back to top

Performance

⬆ back to top

Resources

Learning ES6+

Read This

Tools

Other Style Guides

Other Styles

Further Reading

Books

Blogs

Podcasts

⬆ back to top

In the Wild

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

⬆ back to top

Translation

This style guide is also available in other languages:

The JavaScript Style Guide Guide

Chat With Us About JavaScript

Contributors

License

(The MIT License)

Copyright (c) 2012 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

Amendments

We encourage you to fork this guide and change the rules to fit your team’s style guide. Below, you may list some amendments to the style guide. This allows you to periodically update your style guide without having to deal with merge conflicts.

};

javascript (airbnb/javascript)

正在搜索数据库…

这是什么?这是 Airbnb 发布的一份 JavaScript 风格指南,涵盖类型、变量、函数、类、模块、命名、空格等方面的编码约定,并自称是“一种基本合理的 JavaScript 编写方式”。
这是代码检查工具,还是只是一份文档?它主要是一套成文的编码约定(风格指南),本身并不是可执行的工具,不过大多数规则都会对应到相应的 ESLint 规则,方便你自动执行这些约定。
我到底该怎样把这些规则应用到我的项目里?从这个 monorepo 的 packages 中安装配套的 ESLint 配置(React 项目用 eslint-config-airbnb,普通 JS 项目用 eslint-config-airbnb-base),并配置 Babel,使用 babel-preset-airbnb 加上 airbnb-browser-shims 来提供 polyfill。
遵循这份指南一定要用 Babel 吗?是的,指南默认你会使用 Babel(通过 babel-preset-airbnb),并借助 airbnb-browser-shims 为 ES6+ 特性提供 polyfill,以保证这些特性在各种环境中表现一致。
它涵盖了所有 JavaScript 变体吗,比如 React 或 CSS-in-JS?没有。本仓库只包含核心的 JS 指南;另外还有独立的配套指南,分别针对 React、CSS-in-JavaScript、CSS 与 Sass,以及已弃用的 ES5 指南。
这份指南是怎么组织的?它以一份很长的目录结构呈现,包含编号章节,如类型、引用、对象、数组、解构、字符串、函数、类、命名约定等数十个章节,每条规则都有编号并附有理由说明。
为什么用 const 而不用 var?指南推荐所有变量引用都用 const,只有在需要重新赋值时才用 let,并完全避免使用 var。原因是 const 能防止意外重新赋值导致的 bug,而且 const 和 let 都是块级作用域,不像 var 那样是函数作用域。
这份指南有其他语言的翻译版本吗?有的。README 中说明该指南提供其他语言版本,并设有专门的“翻译”章节,列出了社区翻译版本。
这个项目在 Airbnb 之外还有什么意义?它在 GitHub 上获得了近 15 万颗星,已成为业界应用最广泛的 JavaScript 风格参考之一,也常被其他公司用作 ESLint 配置的基线。
作者
airbnb
大小
3.7 MB
星标
148K
更新
提交Feb 21
时长
14年
提交 · 90 天