1. 在命名对象、函数和实例时使用驼峰命名法(camelCase) ```javascript // bad const OBJEcttsssss = {}; const this_is_my_object = {}; function c() {}

    // good const thisIsMyObject = {}; function thisIsMyFunction() {}

    1. 2. 只有在命名构造器或者类的时候才用帕斯卡拼命名法(PascalCase
    2. ```javascript
    3. // bad
    4. function user(options) {
    5. this.name = options.name;
    6. }
    7. const bad = new user({
    8. name: 'nope',
    9. });
    10. // good
    11. class User {
    12. constructor(options) {
    13. this.name = options.name;
    14. }
    15. }
    16. const good = new User({
    17. name: 'yup',
    18. });
    1. 文件名应该和默认导出的名称完全匹配 ```javascript // file 1 contents class CheckBox { // … } export default CheckBox;

    // file 2 contents export default function fortyTwo() { return 42; }

    // file 3 contents export default function insideDirectory() {}

    // in some other file // bad import CheckBox from ‘./checkBox’; // PascalCase import/export, camelCase filename import FortyTwo from ‘./FortyTwo’; // PascalCase import/filename, camelCase export import InsideDirectory from ‘./InsideDirectory’; // PascalCase import/filename, camelCase export

    // bad import CheckBox from ‘./check_box’; // PascalCase import/export, snake_case filename import forty_two from ‘./forty_two’; // snake_case import/filename, camelCase export import inside_directory from ‘./inside_directory’; // snake_case import, camelCase export import index from ‘./inside_directory/index’; // requiring the index file explicitly import insideDirectory from ‘./insideDirectory/index’; // requiring the index file explicitly

    // good import CheckBox from ‘./CheckBox’; // PascalCase export/import/filename import fortyTwo from ‘./fortyTwo’; // camelCase export/import/filename import insideDirectory from ‘./insideDirectory’; // camelCase export/import/directory name/implicit “index” // ^ supports both insideDirectory.js and insideDirectory/index.js

    1. 4. 当你导出默认函数时使用驼峰命名法。 你的文件名应该和方法名相同
    2. ```javascript
    3. function makeStyleGuide() {
    4. // ...
    5. }
    6. export default makeStyleGuide;
    1. 当你导出一个构造器 / 类 / 单例 / 函数库 / 暴露的对象时应该使用帕斯卡命名法 ```javascript const AirbnbStyleGuide = { es6: { }, };

    export default AirbnbStyleGuide;

    1. 6. 缩略词和缩写都必须是全部大写或者全部小写
    2. ```javascript
    3. // bad
    4. import SmsContainer from './containers/SmsContainer';
    5. // bad
    6. const HttpRequests = [
    7. // ...
    8. ];
    9. // good
    10. import SMSContainer from './containers/SMSContainer';
    11. // good
    12. const HTTPRequests = [
    13. // ...
    14. ];
    15. // also good
    16. const httpRequests = [
    17. // ...
    18. ];
    19. // best
    20. import TextMessageContainer from './containers/TextMessageContainer';
    21. // best
    22. const requests = [
    23. // ...
    24. ];
    1. 你可以大写一个常量,如果它:(1)被导出,(2)使用 const 定义(不能被重新赋值),(3)程序员可以信任它(以及其嵌套的属性)是不变的 ```javascript // bad const PRIVATE_VARIABLE = ‘不应该在文件中不必要地大写’;

    // bad export const THING_TO_BE_CHANGED = ‘会更改的值、显然不应该大写’;

    // bad export let REASSIGNABLE_VARIABLE = ‘不要在大写变量中使用let’;

    // —-

    // 允许,但是不提供语义值 export const apiKey = ‘SOMEKEY’;

    // 多数情况下,很好 export const API_KEY = ‘SOMEKEY’;

    // —-

    // bad - 不必要大写 key 没有增加语义值 export const MAPPING = { KEY: ‘value’ };

    // good export const MAPPING = { key: ‘value’ }; ```