본문 바로가기

개발/Javascript

명명규칙(Naming Conventions)

명명규칙(Naming Conventions)

  • Avoid single letter names. Be descriptive with your naming.

  • 1문자의 이름은 피해 주십시오. 이름으로부터 의도가 읽혀질수 있게 해주십시오.

    // bad
    function q() {
      // ...stuff...
    }
    
    // good
    function query() {
      // ..stuff..
    }
  • Use camelCase when naming objects, functions, and instances.

  • 오브젝트, 함수 그리고 인스턴스에는 camelCase를 사용해 주십시오.

    // bad
    const OBJEcttsssss = {};
    const this_is_my_object = {};
    function c() {}
    
    // good
    const thisIsMyObject = {};
    function thisIsMyFunction() {}
  •  Use PascalCase when naming constructors or classes.

  • 클래스나 constructor에는 PascalCase 를 사용해 주십시오.

    // bad
    function user(options) {
      this.name = options.name;
    }
    
    const bad = new user({
      name: 'nope',
    });
    
    // good
    class User {
      constructor(options) {
        this.name = options.name;
      }
    }
    
    const good = new User({
      name: 'yup',
    });
  • Use a leading underscore _ when naming private properties.

  •  private 프로퍼티명은 선두에 언더스코어 _ 를사용해 주십시오.

    // bad
    this.__firstName__ = 'Panda';
    this.firstName_ = 'Panda';
    
    // good
    this._firstName = 'Panda';
  • Don't save references to this. Use arrow functions or Function#bind.

  • this 의 참조를 보존하는것은 피해주십시오. arrow함수나 Function#bind 를 이용해 주십시오.

    // bad
    function foo() {
      const self = this;
      return function() {
        console.log(self);
      };
    }
    
    // bad
    function foo() {
      const that = this;
      return function() {
        console.log(that);
      };
    }
    
    // good
    function foo() {
      return () => {
        console.log(this);
      };
    }
  • If your file exports a single class, your filename should be exactly the name of the class.

  • 파일을 1개의 클래스로 export 하는 경우, 파일명은 클래스명과 완전히 일치시키지 않으면 안됩니다.

    // file contents
    class CheckBox {
      // ...
    }
    export default CheckBox;
    
    // in some other file
    // bad
    import CheckBox from './checkBox';
    
    // bad
    import CheckBox from './check_box';
    
    // good
    import CheckBox from './CheckBox';
  • Use camelCase when you export-default a function. Your filename should be identical to your function's name.

  • Default export가 함수일 경우, camelCase를 이용해 주십시오. 파일명은 함수명과 동일해야 합니다.

    function makeStyleGuide() {
    }
    
    export default makeStyleGuide;
  • Use PascalCase when you export a singleton / function library / bare object.

  • singleton / function library / 빈오브젝트를 export 하는 경우, PascalCase를 이용해 주십시오.

    const AirbnbStyleGuide = {
      es6: {
      }
    };
    
    export default AirbnbStyleGuide;


'개발 > Javascript' 카테고리의 다른 글

이벤트(Events)  (0) 2018.03.11
억세서(Accessors)  (0) 2018.03.11
형변환과 강제(Type Casting & Coercion)  (0) 2018.03.11
세미콜론(Semicolons)  (0) 2018.03.11
콤마(Commas)  (0) 2018.03.11