8000 GitHub - archiveds/javascript-style-guide: JavaScript Style Guide KOREAN
[go: up one dir, main page]

Skip to content

archiveds/javascript-style-guide

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 

Repository files navigation

์›๋ฌธ:https://github.com/airbnb/javascript

Airbnb JavaScript ์Šคํƒ€์ผ ๊ฐ€์ด๋“œ() {

  1. Types
  2. Objects
  3. Arrays
  4. Strings
  5. Functions
  6. Properties
  7. Variables
  8. Hoisting
  9. Conditional Expressions & Equality
  10. Blocks
  11. Comments
  12. Whitespace
  13. Commas
  14. Semicolons
  15. Type Casting & Coercion
  16. Naming Conventions
  17. Accessors
  18. Constructors
  19. Events
  20. Modules
  21. jQuery
  22. ES5 Compatibility
  23. Testing
  24. Performance
  25. Resources
  26. In the Wild
  27. Translation
  28. The JavaScript Style Guide Guide
  29. Contributors
  30. License
  • Primitives: primitive type์€ ๊ทธ ๊ฐ’์„ ์ง์ ‘ ์กฐ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

    • string
    • number
    • boolean
    • null
    • undefined
    var foo = 1,
        bar = foo;
    
    bar = 9;
    
    console.log(foo, bar); // => 1, 9
  • Complex: ์ฐธ์กฐํ˜•(Complex)์€ ์ฐธ์กฐ๋ฅผ ํ†ตํ•ด ๊ฐ’์„ ์กฐ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

    • object
    • array
    • function
    var foo = [1, 2],
        bar = foo;
    
    bar[0] = 9;
    
    console.log(foo[0], bar[0]); // => 9, 9

    [โฌ†]

  • Object๋ฅผ ๋งŒ๋“ค ๋•Œ๋Š” ๋ฆฌํ„ฐ๋Ÿด ๊ตฌ๋ฌธ์„ ์‚ฌ์šฉํ•˜์‹ญ์‹œ์˜ค.

    // bad
    var item = new Object();
    
    // good
    var item = {};
  • ์˜ˆ์•ฝ์–ด(reserved words)๋ฅผ ํ‚ค๋กœ ์‚ฌ์šฉํ•˜์ง€ ๋งˆ์‹ญ์‹œ์˜ค. ์ด๊ฒƒ์€ IE8์—์„œ ๋™์ž‘ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. More info

    // bad
    var superman = {
      default: { clark: 'kent' },
      private: true
    };
    
    // good
    var superman = {
      defaults: { clark: 'kent' },
      hidden: true
    };
  • ์˜ˆ์•ฝ์–ด ๋Œ€์‹  ์•Œ๊ธฐ ์‰ฌ์šด ๋™์˜์–ด(readable synonyms)๋ฅผ ์‚ฌ์šฉํ•˜์‹ญ์‹œ์˜ค.

    // bad
    var superman = {
      class: 'alien'
    };
    
    // bad
    var superman = {
      klass: 'alien'
    };
    
    // good
    var superman = {
      type: 'alien'
    };

    [โฌ†]

  • ๋ฐฐ์—ด์„ ๋งŒ๋“ค ๋•Œ ๋ฆฌํ„ฐ๋Ÿด ๊ตฌ๋ฌธ์„ ์‚ฌ์šฉํ•˜์‹ญ์‹œ์˜ค.

    // bad
    var items = new Array();
    
    // good
    var items = [];
  • ๊ธธ์ด๋ฅผ ์•Œ ์ˆ˜์—†๋Š” ๊ฒฝ์šฐ๋Š” Array#push๋ฅผ ์‚ฌ์šฉํ•˜์‹ญ์‹œ์˜ค.

    var someStack = [];
    
    
    // bad
    someStack[someStack.length] = 'abracadabra';
    
    // good
    someStack.push('abracadabra');
  • ๋ฐฐ์—ด์„ ๋ณต์‚ฌ ํ•  ํ•„์š”๊ฐ€์žˆ๋Š” ๊ฒฝ์šฐ Array#slice๋ฅผ ์‚ฌ์šฉํ•˜์‹ญ์‹œ์˜ค. jsPerf

    var len = items.length,
        itemsCopy = [],
        i;
    
    // bad
    for (i = 0; i < len; i++) {
      itemsCopy[i] = items[i];
    }
    
    // good
    itemsCopy = items.slice();
  • Array์™€ ๋น„์Šทํ•œ(Array-Like)ํ•œ Object๋ฅผ Array์— ๋ณ€ํ™˜ํ•˜๋Š” ๊ฒฝ์šฐ๋Š” Array#slice๋ฅผ ์‚ฌ์šฉํ•˜์‹ญ์‹œ์˜ค.

    function trigger() {
      var args = Array.prototype.slice.call(arguments);
      ...
    }

[โฌ†]

  • ๋ฌธ์ž์—ด์€ ์ž‘์€ ๋”ฐ์˜ดํ‘œ''๋ฅผ ์‚ฌ์šฉํ•˜์‹ญ์‹œ์˜ค.

    // bad
    var name = "Bob Parr";
    
    // good
    var name = 'Bob Parr';
    
    // bad
    var fullName = "Bob " + this.lastName;
    
    // good
    var fullName = 'Bob ' + this.lastName;
  • 80 ๋ฌธ์ž ์ด์ƒ์˜ ๋ฌธ์ž์—ด์€ ๋ฌธ์ž์—ด ์—ฐ๊ฒฐ์„ ์‚ฌ์šฉํ•˜์—ฌ ์—ฌ๋Ÿฌ ์ค„์— ๊ฑธ์ณ ๊ธฐ์ˆ  ํ•  ํ•„์š”๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

  • Note : ๋ฌธ์ž์—ด ์—ฐ๊ฒฐ์„ ๋งŽ์ดํ•˜๋ฉด ์„ฑ๋Šฅ์— ์˜ํ–ฅ์„ ์ค„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. jsPerf & Discussion

    // bad
    var errorMessage = 'This is a super long error that was thrown because of Batman. When you stop to think about how Batman had anything to do with this, you would get nowhere fast.';
    
    // bad
    var errorMessage = 'This is a super long error that \
    was thrown because of Batman. \
    When you stop to think about \
    how Batman had anything to do \
    with this, you would get nowhere \
    fast.';
    
    
    // good
    var errorMessage = 'This is a super long error that ' +
      'was thrown because of Batman.' +
      'When you stop to think about ' +
      'how Batman had anything to do ' +
      'with this, you would get nowhere ' +
      'fast.';
  • ํ”„๋กœ๊ทธ๋žจ์—์„œ ๋ฌธ์ž์—ด์„ ์ƒ์„ฑ ํ•  ํ•„์š”๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ (ํŠนํžˆ IE๋Š”) ๋ฌธ์ž์—ด ์—ฐ๊ฒฐ ๋Œ€์‹  Array#join์„ ์‚ฌ์šฉํ•˜์‹ญ์‹œ์˜ค. jsPerf.

    var items,
        messages,
        length,
        i;
    
    messages = [{
        state: 'success',
        message: 'This one worked.'
    },{
        state: 'success',
        message: 'This one worked as well.'
    },{
        state: 'error',
        message: 'This one did not work.'
    }];
    
    length = messages.length;
    
    // bad
    function inbox(messages) {
      items = '<ul>';
    
      for (i = 0; i < length; i++) {
        items += '<li>' + messages[i].message + '</li>';
      }
    
      return items + '</ul>';
    }
    
    // good
    function inbox(messages) {
      items = [];
    
      for (i = 0; i < length; i++) {
        items[i] = messages[i].message;
      }
    
      return '<ul><li>' + items.join('</li><li>') + '</li></ul>';
    }

    [โฌ†]

  • ํ•จ์ˆ˜์‹(Function expressions)

    // ์ต๋ช…ํ•จ์ˆ˜์‹(anonymous function expression)
    var anonymous = function() {
      return true;
    };
    
    // ๋ช…๋ช…๋œ ํ•จ์ˆ˜์‹(named function expression)
    var named = function named() {
      return true;
    };
    
    // ์ฆ‰์‹œ์‹คํ–‰ ํ•จ์ˆ˜์‹(immediately-invoked function expression (IIFE))
    (function() {
      console.log('Welcome to the Internet. Please follow me.');
    })();
  • (if ๋ฐ while ๋“ฑ) ๋ธ”๋ก ๋‚ด์—์„œ ๋ณ€์ˆ˜์— ํ•จ์ˆ˜๋ฅผ ํ• ๋‹นํ•˜๋Š” ๋Œ€์‹  ํ•จ์ˆ˜๋ฅผ ์„ ์–ธํ•˜์ง€ ๋งˆ์‹ญ์‹œ์˜ค. ๋ธŒ๋ผ์šฐ์ €๋Š” ํ—ˆ์šฉํ•˜์ง€๋งŒ (๋งˆ์น˜ 'bad news bears'์ฒ˜๋Ÿผ) ๋ชจ๋‘ ๋‹ค๋ฅธ ๋ฐฉ์‹์œผ๋กœ ํ•ด์„๋ฉ๋‹ˆ๋‹ค.

  • Note: ECMA-262์—์„œ๋Š”block์€ statements์˜ ๋ชฉ๋ก์— ์ •์˜๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค ๋งŒ, ํ•จ์ˆ˜ ์„ ์–ธ์€ statements๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. ์ด ๋ฌธ์ œ๋Š” ECMA-262์˜ ์„ค๋ช…์„ ์ฐธ์กฐํ•˜์‹ญ์‹œ์˜ค. .

    // bad
    if (currentUser) {
      function test() {
        console.log('Nope.');
      }
    }
    
    // good
    var test;
    if (currentUser) {
      test = function test() {
        console.log('Yup.');
      };
    }
  • ๋งค๊ฐœ ๋ณ€์ˆ˜(parameter)์— arguments๋ฅผ ์ ˆ๋Œ€ ์ง€์ •ํ•˜์ง€ ๋งˆ์‹ญ์‹œ์˜ค. ์ด๊ฒƒ์€ ํ•จ์ˆ˜ ๋ฒ”์œ„๋กœ ์ „๋‹ฌ ๋ arguments๊ฐ์ฒด์˜ ์ฐธ์กฐ๋ฅผ ๋ฎ์–ด ์“ธ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

    // bad
    function nope(name, options, arguments) {
      // ...stuff...
    }
    
    // good
    function yup(name, options, args) {
      // ...stuff...
    }

    [โฌ†]

  • ์†์„ฑ์— ์•ก์„ธ์Šคํ•˜๋ ค๋ฉด ๋„ํŠธ.๋ฅผ ์‚ฌ์šฉํ•˜์‹ญ์‹œ์˜ค.

    var luke = {
      jedi: true,
      age: 28
    };
    
    // bad
    var isJedi = luke['jedi'];
    
    // good
    var isJedi = luke.jedi;
  • ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์†์„ฑ์— ์ ‘๊ทผํ•˜๋ ค๋ฉด ๋Œ€๊ด„ํ˜ธ[]์„ ์‚ฌ์šฉํ•˜์‹ญ์‹œ์˜ค.

    var luke = {
      jedi: true,
      age: 28
    };
    
    function getProp(prop) {
      return luke[prop];
    }
    
    var isJedi = getProp('jedi');

    [โฌ†]

  • ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธ ํ•  ๋•Œ๋Š” ํ•ญ์ƒ var๋ฅผ ์‚ฌ์šฉํ•˜์‹ญ์‹œ์˜ค. ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด ์ „์—ญ ๋ณ€์ˆ˜๋กœ ์„ ์–ธ๋ฉ๋‹ˆ๋‹ค. ์ „์—ญ ๋„ค์ž„ ์ŠคํŽ˜์ด์Šค๋ฅผ ์˜ค์—ผ์‹œํ‚ค์ง€ ์•Š๋„๋ก Captain Planet๋„ ๊ฒฝ๊ณ ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

    // bad
    superPower = new SuperPower();
    
    // good
    var superPower = new SuperPower();
  • ์—ฌ๋Ÿฌ ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•˜๋ ค๋ฉด ํ•˜๋‚˜์˜ var๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ณ€์ˆ˜๋งˆ๋‹ค ์ค„๋ฐ”๊ฟˆํ•˜์—ฌ ์„ ์–ธํ•˜์‹ญ์‹œ์˜ค.

    // bad
    var items = getItems();
    var goSportsTeam = true;
    var dragonball = 'z';
    
    // good
    var items = getItems(),
        goSportsTeam = true,
        dragonball = 'z';
  • ์ •์˜๋˜์ง€ ์•Š์€ ๋ณ€์ˆ˜๋ฅผ ๋งˆ์ง€๋ง‰์œผ๋กœ ์„ ์–ธํ•˜์‹ญ์‹œ์˜ค. ์ด๊ฒƒ์€ ๋‚˜์ค‘์— ์ด๋ฏธ ํ• ๋‹น๋œ ๋ณ€์ˆ˜ ์ค‘ ํ•˜๋‚˜๋ฅผ ์ง€์ •ํ•ด์•ผํ•˜๋Š” ๊ฒฝ์šฐ์— ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค.

    // bad
    var i, len, dragonball,
        items = getItems(),
        goSportsTeam = true;
    
    // bad
    var i, items = getItems(),
        dragonball,
        goSportsTeam = true,
        len;
    
    // good
    var items = getItems(),
        goSportsTeam = true,
        dragonball,
        length,
        i;
  • ๋ณ€์ˆ˜์˜ ํ• ๋‹น์€ ์Šค์ฝ”ํ”„์˜ ์‹œ์ž‘ ๋ถ€๋ถ„์—์„œ ํ•ด์ฃผ์‹ญ์‹œ์˜ค. ์ด๊ฒƒ์€ ๋ณ€์ˆ˜ ์„ ์–ธ๊ณผ Hoisting ๊ด€๋ จ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•ฉ๋‹ˆ๋‹ค.

    // bad
    function() {
      test();
      console.log('doing stuff..');
    
      //..other stuff..
    
      var name = getName();
    
      if (name === 'test') {
        return false;
      }
    
      return name;
    }
    
    // good
    function() {
      var name = getName();
    
      test();
      console.log('doing stuff..');
    
      //..other stuff..
    
      if (name === 'test') {
        return false;
      }
    
      return name;
    }
    
    // bad
    function() {
      var name = getName();
    
      if (!arguments.length) {
        return false;
      }
    
      return true;
    }
    
    // good
    function() {
      if (!arguments.length) {
        return false;
      }
    
      var name = getName();
    
      return true;
    }

    [โฌ†]

  • ํ•ด๋‹น ์Šค์ฝ”ํ”„์˜ ์‹œ์ž‘ ๋ถ€๋ถ„์— Hoist๋œ ๋ณ€์ˆ˜์„ ์–ธ์€ ํ• ๋‹น๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

    // (notDefined๊ฐ€ ์ „์—ญ ๋ณ€์ˆ˜์— ์กด์žฌํ•˜์ง€ ์•Š๋Š”๋‹ค๊ณ  ๊ฐ€์ •ํ–ˆ์„ ๊ฒฝ์šฐ)
    // ์ด๊ฒƒ์€ ๋™์ž‘ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
    function example() {
      console.log(notDefined); // => throws a ReferenceError
    }
    
    // ๊ทธ ๋ณ€์ˆ˜๋ฅผ ์ฐธ์กฐํ•˜๋Š” ์ฝ”๋“œ ํ›„์— ๊ทธ ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธ ํ•œ ๊ฒฝ์šฐ
    // ๋ณ€์ˆ˜๊ฐ€ Hoist๋œ ์ƒํƒœ์—์„œ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค.
    // Note : `true`๋ผ๋Š” ๊ฐ’ ์ž์ฒด๋Š” Hoist๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
    function example() {
      console.log(declaredButNotAssigned); // => undefined
      var declaredButNotAssigned = true;
    }
    
    // ์ธํ„ฐ ํ”„๋ฆฐํ„ฐ๋Š” ๋ณ€์ˆ˜ ์„ ์–ธ์„ ์Šค์ฝ”ํ”„์˜ ์‹œ์ž‘ ๋ถ€๋ถ„์— Hoistํ•ฉ๋‹ˆ๋‹ค.
    // ์œ„์˜ ์˜ˆ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋‹ค์‹œ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    function example() {
      var declaredButNotAssigned;
      console.log(declaredButNotAssigned); // => undefined
      declaredButNotAssigned = true;
    }
  • ์ต๋ช… ํ•จ์ˆ˜์˜ ๊ฒฝ์šฐ ํ•จ์ˆ˜๊ฐ€ ํ• ๋‹น๋˜๊ธฐ ์ „์— ๋ณ€์ˆ˜๊ฐ€ Hoist๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    function example() {
      console.log(anonymous); // => undefined
    
      anonymous(); // => TypeError anonymous is not a function
    
      var anonymous = function() {
        console.log('anonymous function expression');
      };
    }
  • ๋ช…๋ช… ๋œ ํ•จ์ˆ˜์˜ ๊ฒฝ์šฐ๋„ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ๋ณ€์ˆ˜๊ฐ€ Hoist๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ•จ์ˆ˜ ์ด๋ฆ„๊ณผ ํ•จ์ˆ˜ ๋ณธ์ฒด๋Š” Hoist๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

    function example() {
      console.log(named); // => undefined
    
      named(); // => TypeError named is not a function
    
      superPower(); // => ReferenceError superPower is not defined
    
      var named = function superPower() {
        console.log('Flying');
      };
    }
    
    // ํ•จ์ˆ˜์ด๋ฆ„๊ณผ ๋ณ€์ˆ˜์ด๋ฆ„์ด ๊ฐ™์€ ๊ฒฝ์šฐ์—๋„ ๊ฐ™์€ ์ผ์ด ์ผ์–ด๋‚ฉ๋‹ˆ๋‹ค.
    function example() {
      console.log(named); // => undefined
    
      named(); // => TypeError named is not a function
    
      var named = function named() {
        console.log('named');
      }
    }
  • ํ•จ์ˆ˜ ์„ ์–ธ์€ ํ•จ์ˆ˜์ด๋ฆ„๊ณผ ํ•จ์ˆ˜๋ณธ๋ฌธ์ด Hoist๋ฉ๋‹ˆ๋‹ค.

    function example() {
      superPower(); // => Flying
    
      function superPower() {
        console.log('Flying');
      }
    }
  • ๋” ์ž์„ธํ•œ ์ •๋ณด๋Š” Ben Cherry์˜ JavaScript Scoping & Hoisting๋ฅผ ์ฐธ์กฐํ•˜์‹ญ์‹œ์˜ค.

    [โฌ†]

  • == ๋‚˜ != ๋ณด๋‹ค๋Š” === ์™€ !== ๋ฅผ ์‚ฌ์šฉํ•ด ์ฃผ์‹ญ์‹œ์˜ค

  • ์กฐ๊ฑด์‹์€ToBoolean ๋ฉ”์†Œ๋“œ์— ์˜ํ•ด ์—„๋ฐ€ํ•˜๊ฒŒ ๋น„๊ต๋ฉ๋‹ˆ๋‹ค. ํ•ญ์ƒ ์ด ๊ฐ„๋‹จํ•œ ๊ทœ์น™์— ๋”ฐ๋ผ ์ฃผ์‹ญ์‹œ์˜ค.

    • Objects ๋Š” true ๋กœ ํ‰๊ฐ€๋ฉ๋‹ˆ๋‹ค.
    • undefined ๋Š” false ๋กœ ํ‰๊ฐ€๋ฉ๋‹ˆ๋‹ค.
    • null ๋Š” false ๋กœ ํ‰๊ฐ€๋ฉ๋‹ˆ๋‹ค.
    • Booleans ๋Š” booleanํ˜•์˜ ๊ฐ’ ์œผ๋กœ ํ‰๊ฐ€๋ฉ๋‹ˆ๋‹ค.
    • Numbers ๋Š” true ๋กœ ํ‰๊ฐ€๋ฉ๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ +0, -0, or NaN ์˜ ๊ฒฝ์šฐ๋Š” false ์ž…๋‹ˆ๋‹ค.
    • Strings ๋Š” true ๋กœ ํ‰๊ฐ€๋ฉ๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ๋นˆ๋ฌธ์ž '' ์˜ ๊ฒฝ์šฐ๋Š” false ์ž…๋‹ˆ๋‹ค.
    if ([0]) {
      // true
      // Array๋Š” Object ์ด๋ฏ€๋กœ true ๋กœ ํ‰๊ฐ€๋ฉ๋‹ˆ๋‹ค.
    }
  • ์งง์€ํ˜•์‹์„ ์‚ฌ์šฉํ•˜์‹ญ์‹œ์˜ค.

    // bad
    if (name !== '') {
      // ...stuff...
    }
    
    // good
    if (name) {
      // ...stuff...
    }
    
    // bad
    if (collection.length > 0) {
      // ...stuff...
    }
    
    // good
    if (collection.length) {
      // ...stuff...
    }
  • ๋” ์ž์„ธํ•œ ์ •๋ณด๋Š” Angus Croll ์˜ Truth Equality and JavaScript๋ฅผ ์ฐธ๊ณ ํ•ด ์ฃผ์‹ญ์‹œ์˜ค.

    [โฌ†]

  • ๋ณต์ˆ˜ํ–‰ ๋ธ”๋ก์€ ์ค‘๊ด„ํ˜ธ ({})๋ฅผ ์‚ฌ์šฉํ•˜์‹ญ์‹œ์˜ค.

    // bad
    if (test)
      return false;
    
    // good
    if (test) return false;
    
    // good
    if (test) {
      return false;
    }
    
    // bad
    function() { return false; }
    
    // good
    function() {
      return false;
    }

    [โฌ†]

  • ๋ณต์ˆ˜ํ–‰์˜ ์ฝ”๋ฉ˜ํŠธ๋Š” /** ... */ ๋ฅผ ์‚ฌ์šฉํ•ด ์ฃผ์‹ญ์‹œ์˜ค. ๊ทธ ์•ˆ์—๋Š” ์„ค๋ช…๊ณผ ๋ชจ๋“  ๋งค๊ฐœ ๋ณ€์ˆ˜์™€ ๋ฐ˜ํ™˜ ๊ฐ’์— ๋Œ€ํ•œ ํ˜•์‹๊ณผ ๊ฐ’์„ ์„ค๋ช…ํ•ฉ๋‹ˆ๋‹ค.

    // bad
    // make() returns a new element
    // based on the passed in tag name
    //
    // @param <String> tag
    // @return <Element> element
    function make(tag) {
    
      // ...stuff...
    
      return element;
    }
    
    // good
    /**
     * make() returns a new element
     * based on the passed in tag name
     *
     * @param <String> tag
     * @return <Element> element
     */
    function make(tag) {
    
      // ...stuff...
    
      return element;
    }
  • ํ•œ ์ค„ ์ฃผ์„์—๋Š”//๋ฅผ ์‚ฌ์šฉํ•˜์‹ญ์‹œ์˜ค. ์ฝ”๋ฉ˜ํŠธ๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ  ์‹ถ์€ ์ฝ”๋“œ์˜ ์ƒ๋‹จ์— ์ž‘์„ฑํ•˜์‹ญ์‹œ์˜ค. ๋˜ํ•œ ์ฃผ์„ ์•ž์— ๋นˆ ์ค„์„ ๋„ฃ์–ด์ฃผ์‹ญ์‹œ์˜ค.

    // bad
    var active = true;  // is current tab
    
    // good
    // is current tab
    var active = true;
    
    // bad
    function getType() {
      console.log('fetching type...');
      // set the default type to 'no type'
      var type = this._type || 'no type';
    
      return type;
    }
    
    // good
    function getType() {
      console.log('fetching type...');
    
      // set the default type to 'no type'
      var type = this._type || 'no type';
    
      return type;
    }
  • ๋ฌธ์ œ๋ฅผ ์ง€์ ํ•˜๊ณ  ์žฌ๊ณ ๋ฅผ ์ด‰๊ตฌํ•˜๊ฑฐ๋‚˜ ๋ฌธ์ œ์— ๋Œ€ํ•œ ํ•ด๊ฒฐ์ฑ…์„ ์ œ์‹œํ•˜๋Š” ๋“ฑ ์˜๊ฒฌ์˜ ์•ž์— FIXME ๋‚˜ TODO๋ฅผ ๋ถ™์ด๋Š” ๊ฒƒ์œผ๋กœ ๋‹ค๋ฅธ ๊ฐœ๋ฐœ์ž์˜ ๋น ๋ฅธ ์ดํ•ด๋ฅผ ๋„์šธ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ์–ด๋–ค ์•ก์…˜์„ ๋™๋ฐ˜ํ•œ๋‹ค๋Š” ์˜๋ฏธ์—์„œ ์ผ๋ฐ˜ ์ฝ”๋ฉ˜ํŠธ์™€๋Š” ๋‹ค๋ฆ…๋‹ˆ๋‹ค. ์•ก์…˜์€ FIXME - ํ•ด๊ฒฐ์ฑ…์ด ํ•„์š” ๋˜๋Š” TODO - ๊ตฌํ˜„์ด ํ•„์š” ์ž…๋‹ˆ๋‹ค.

  • ๋ฌธ์ œ์— ๋Œ€ํ•œ ์ฝ”๋ฉ˜ํŠธ๋กœ // FIXME :๋ฅผ ์‚ฌ์šฉํ•˜์‹ญ์‹œ์˜ค.

    function Calculator() {
    
      // FIXME: ์ „์—ญ ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด์„œ๋Š” ์•ˆ๋ฉ๋‹ˆ๋‹ค.
      total = 0;
    
      return this;
    }
  • ๋ฌธ์ œ ํ•ด๊ฒฐ์ฑ…์— ๋Œ€ํ•œ ์ฝ”๋ฉ˜ํŠธ๋กœ // TODO :๋ฅผ ์‚ฌ์šฉํ•˜์‹ญ์‹œ์˜ค.

    function Calculator() {
    
      // TODO: total์€ ์˜ต์…˜ ๋งค๊ฐœ ๋ณ€์ˆ˜๋กœ ์„ค์ •๋˜์–ด์•ผ ํ•จ.
      this.total = 0;
      return this;
    }

  **[[โฌ†]](#TOC)**


## <a name='whitespace'>Whitespace</a> [์›๋ฌธ](https://github.com/airbnb/javascript#whitespace)

- ํƒญ์—๋Š” ๊ณต๋ฐฑ 2๊ฐœ๋ฅผ ์„ค์ •ํ•˜์‹ญ์‹œ์˜ค.

  ```javascript
  // bad
  function() {
  โˆ™โˆ™โˆ™โˆ™var name;
  }

  // bad
  function() {
  โˆ™var name;
  }

  // good
  function() {
  โˆ™โˆ™var name;
  }
  ```
- ์ค‘๊ด„ํ˜ธ({})์˜ ์•ž์— ๊ณต๋ฐฑ์„ ํ•˜๋‚˜ ๋„ฃ์–ด์ฃผ์‹ญ์‹œ์˜ค.

  ```javascript
  // bad
  function test(){
    console.log('test');
  }

  // good
  function test() {
    console.log('test');
  }

  // bad
  dog.set('attr',{
    age: '1 year',
    breed: 'Bernese Mountain Dog'
  });

  // good
  dog.set('attr', {
    age: '1 year',
    breed: 'Bernese Mountain Dog'
  });
  ```
- ํŒŒ์ผ์˜ ๋งˆ์ง€๋ง‰์—๋Š” ๋นˆ ์ค„์„ ํ•˜๋‚˜ ๋„ฃ์–ด์ฃผ์‹ญ์‹œ์˜ค.

  ```javascript
  // bad
  (function(global) {
    // ...stuff...
  })(this);
  ```

  ```javascript
  // good
  (function(global) {
    // ...stuff...
  })(this);

  ```

- ๋ฉ”์†Œ๋“œ ์ฒด์ธ์ด ๊ธธ์–ด์ง€๋Š” ๊ฒฝ์šฐ ์ ์ ˆํžˆ ๋“ค์—ฌ์“ฐ๊ธฐ(indentation) ํ•˜์‹ญ์‹œ์˜ค.

  ```javascript
  // bad
  $('#items').find('.selected').highlight().end().find('.open').updateCount();

  // good
  $('#items')
    .find('.selected')
      .highlight()
      .end()
    .find('.open')
      .updateCount();

  // bad
  var leds = stage.selectAll('.led').data(data).enter().append('svg:svg').class('led', true)
      .attr('width',  (radius + margin) * 2).append('svg:g')
      .attr('transform', 'translate(' + (radius + margin) + ',' + (radius + margin) + ')')
      .call(tron.led);

  // good
  var leds = stage.selectAll('.led')
      .data(data)
    .enter().append('svg:svg')
      .class('led', true)
      .attr('width',  (radius + margin) * 2)
    .append('svg:g')
      .attr('transform', 'translate(' + (radius + margin) + ',' + (radius + margin) + ')')
      .call(tron.led);
  ```

  **[[โฌ†]](#TOC)**

## <a name='commas'>Commas</a> [์›๋ฌธ](https://github.com/airbnb/javascript#commas)

- ์„ ๋‘์˜ comma๋Š” **ํ•˜์ง€๋งˆ์‹ญ์‹œ์˜ค.**

  ```javascript
  // bad
  var once
    , upon
    , aTime;

  // good
  var once,
      upon,
      aTime;

  // bad
  var hero = {
      firstName: 'Bob'
    , lastName: 'Parr'
    , heroName: 'Mr. Incredible'
    , superPower: 'strength'
  };

  // good
  var hero = {
    firstName: 'Bob',
    lastName: 'Parr',
    heroName: 'Mr. Incredible',
    superPower: 'strength'
  };
  ```

ใ€€- ๋ง๋ฏธ์˜ ๋ถˆํ•„์š”ํ•œ ์‰ผํ‘œ๋„ **ํ•˜์ง€ ๋งˆ์‹ญ์‹œ์˜ค.** ์ด๊ฒƒ์€ IE6/7๊ณผ quirksmode์˜ IE9์—์„œ ๋ฌธ์ œ๋ฅผ ์ผ์œผํ‚ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
๋˜ํ•œ ES3์˜ ์ผ๋ถ€ ๊ตฌํ˜„์—์„œ ๋ถˆํ•„์š”ํ•œ ์‰ผํ‘œ๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ, ๋ฐฐ์—ด ๊ธธ์ด๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.
์ด๊ฒƒ์€ ES5์—์„œ ๋ถ„๋ช…ํ•ด์กŒ์Šต๋‹ˆ๋‹ค.([source](http://es5.github.io/#D)):

> ์ œ 5 ํŒ์—์„œ๋Š” ๋ง๋ฏธ์˜ ๋ถˆํ•„์š”ํ•œ ์‰ผํ‘œ๊ฐ€ ์žˆ๋Š” ArrayInitialiser (๋ฐฐ์—ด ์ดˆ๊ธฐํ™” ์—ฐ์‚ฐ์ž)๋ผ๋„ ๋ฐฐ์—ด์— ๊ธธ์ด๋ฅผ ์ถ”๊ฐ€ํ•˜์ง€ ์•Š๋Š”๋‹ค๋Š” ์‚ฌ์‹ค์„ ๋ช…ํ™•ํžˆํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๊ฒƒ์€ ์ œ 3 ํŒ์—์„œ ์˜๋ฏธ์ ์ธ ๋ณ€๊ฒฝ์€ ์•„๋‹™๋‹ˆ๋‹ค๋งŒ, ์ผ๋ถ€์˜ ๊ตฌํ˜„์€ ์ด์ „๋ถ€ํ„ฐ ์ด๊ฒƒ์„ ์˜คํ•ดํ•˜๊ณ  ์žˆ์—ˆ์„์ง€๋„ ๋ชจ๋ฆ…๋‹ˆ๋‹ค.

  ```javascript
  // bad
  var hero = {
    firstName: 'Kevin',
    lastName: 'Flynn',
  };

  var heroes = [
    'Batman',
    'Superman',
  ];

  // good
  var hero = {
    firstName: 'Kevin',
    lastName: 'Flynn'
  };

  var heroes = [
    'Batman',
    'Superman'
  ];
  ```

  **[[โฌ†]](#TOC)**


## <a name='semicolons'>Semicolons</a> [์›๋ฌธ](https://github.com/airbnb/javascript#semicolons)

- **๋„ค!(Yup.)**

  ```javascript
  // bad
  (function() {
    var name = 'Skywalker'
    return name
  })()

  // good
  (function() {
    var name = 'Skywalker';
    return name;
  })();

  // good
  ;(function() {
    var name = 'Skywalker';
    return name;
  })();
  ```

  **[[โฌ†]](#TOC)**


## <a name='type-coercion'>Type Casting & Coercion(๊ฐ•์ œ)</a> [์›๋ฌธ](https://github.com/airbnb/javascript#type-coercion)

- ๋ฌธ์˜ ์‹œ์ž‘ ๋ถ€๋ถ„์—์„œ ํ˜•์„ ๊ฐ•์ œํ•ฉ๋‹ˆ๋‹ค.
- Strings:

  ```javascript
  //  => this.reviewScore = 9;

  // bad
  var totalScore = this.reviewScore + '';

  // good
  var totalScore = '' + this.reviewScore;

  // bad
  var totalScore = '' + this.reviewScore + ' total score';

  // good
  var totalScore = this.reviewScore + ' total score';
  ```

- ์ˆซ์ž๋Š”`parseInt`๋ฅผ ์‚ฌ์šฉํ•˜์‹ญ์‹œ์˜ค. ํ•ญ์ƒ ํ˜•๋ณ€ํ™˜์„ ์œ„ํ•œ ๊ธฐ์ˆ˜(radix)๋ฅผ ์ธ์ˆ˜๋กœ ์ „๋‹ฌํ•˜์‹ญ์‹œ์˜ค.

  ```javascript
  var inputValue = '4';

  // bad
  var val = new Number(inputValue);

  // bad
  var val = +inputValue;

  // bad
  var val = inputValue >> 0;

  // bad
  var val = parseInt(inputValue);

  // good
  var val = Number(inputValue);

  // good
  var val = parseInt(inputValue, 10);
  ```

- ์–ด๋–ค ์ด์œ ์— ์˜ํ•ด `parseInt` ๊ฐ€ ๋ณ‘๋ชฉ์ด ๋˜๊ณ , [์„ฑ๋Šฅ์ ์ธ ์ด์œ ](http://jsperf.com/coercion-vs-casting/3)๋กœ Bitshift๋ฅผ ์‚ฌ์šฉํ•  ํ•„์š”๊ฐ€ ์žˆ์„ ๊ฒฝ์šฐ,
ํ•˜๋ ค๊ณ  ํ•˜๋Š”๊ฒƒ์— ๋Œ€ํ•ด, why(์™œ)์™€ what(๋ฌด์—‡)์˜ ์„ค๋ช…์„ ์ฝ”๋ฉ˜ํŠธ๋กœ ๋‚จ๊ฒจ์ฃผ์‹ญ์‹œ์˜ค.

  ```javascript
  // good
  /**
   * parseInt๊ฐ€ ๋ณ‘๋ชฉ์„ ์ผ์œผํ‚ค๋ฏ€๋กœ
   * Bitshift๋กœ ๋ฌธ์ž์—ด์„ ์ˆ˜์น˜๋กœ ๊ฐ•์ œ์ ์œผ๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ๋ฐฉ๋ฒ•์œผ๋กœ
   * ์„ฑ๋Šฅ์„ ๊ฐœ์„ ์‹œํ‚ต๋‹ˆ๋‹ค.
   */
  var val = inputValue >> 0;
  ```

- Booleans:

  ```javascript
  var age = 0;

  // bad
  var hasAge = new Boolean(age);

  // good
  var hasAge = Boolean(age);

  // good
  var hasAge = !!age;
  ```

  **[[โฌ†]](#TOC)**


## <a name='naming-conventions'>Naming Conventions</a> [์›๋ฌธ](https://github.com/airbnb/javascript#naming-conventions)

- ํ•œ๋ฌธ์ž ์ด๋ฆ„์€ ํ”ผํ•˜์‹ญ์‹œ์˜ค. ์ด๋ฆ„์—์„œ ์˜๋„๋ฅผ ์ฝ์„ ์ˆ˜ ์žˆ๋„๋ก ํ•˜์‹ญ์‹œ์˜ค.

  ```javascript
  // bad
  function q() {
    // ...stuff...
  }

  // good
  function query() {
    // ..stuff..
  }
  ```

- Object, ํ•จ์ˆ˜, ๊ทธ๋ฆฌ๊ณ  ์ธ์Šคํ„ด์Šค๋กœ๋Š” camelCase๋ฅผ ์‚ฌ์šฉํ•˜์‹ญ์‹œ์˜ค.

  ```javascript
  // bad
  var OBJEcttsssss = {};
  var this_is_my_object = {};
  var this-is-my-object = {};
  function c() {};
  var u = new user({
    name: 'Bob Parr'
  });

  // good
  var thisIsMyObject = {};
  function thisIsMyFunction() {};
  var user = new User({
    name: 'Bob Parr'
  });
  ```

- Class์™€ ์ƒ์„ฑ์ž์—๋Š” PascalCase๋ฅผ ์‚ฌ์šฉํ•˜์‹ญ์‹œ์˜ค.

  ```javascript
  // bad
  function user(options) {
    this.name = options.name;
  }

  var bad = new user({
    name: 'nope'
  });

  // good
  function User(options) {
    this.name = options.name;
  }

  var good = new User({
    name: 'yup'
  });
  ```

- private ์†์„ฑ ์ด๋ฆ„์€ ๋ฐ‘์ค„ `_` ์„ ์‚ฌ์šฉํ•˜์‹ญ์‹œ์˜ค.

  ```javascript
  // bad
  this.__firstName__ = 'Panda';
  this.firstName_ = 'Panda';

  // good
  this._firstName = 'Panda';
  ```

- `this`์˜ ์ฐธ์กฐ๋ฅผ ์ €์žฅํ•  ๋•Œ `_this` ๋ฅผ ์‚ฌ์šฉํ•˜์‹ญ์‹œ์˜ค.

  ```javascript
  // bad
  function() {
    var self = this;
    return function() {
      console.log(self);
    };
  }

  // bad
  function() {
    var that = this;
    return function() {
      console.log(that);
    };
  }

  // good
  function() {
    var _this = this;
    return function() {
      console.log(_this);
    };
  }
  ```

- ํ•จ์ˆ˜์— ์ด๋ฆ„์„ ๋ถ™์—ฌ์ฃผ์‹ญ์‹œ์˜ค. ์ด๊ฒƒ์€ stack traces๋ฅผ ์ถ”์ ํ•˜๊ธฐ ์‰ฝ๊ฒŒํ•˜๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.

  ```javascript
  // bad
  var log = function(msg) {
    console.log(msg);
  };

  // good
  var log = function log(msg) {
    console.log(msg);
  };
  ```

  **[[โฌ†]](#TOC)**


## <a name='accessors'>Accessors</a> [์›๋ฌธ](https://github.com/airbnb/javascript#accessors)

- ์†์„ฑ์„ ์œ„ํ•œ ์ ‘๊ทผ์ž(Accessor) ํ•จ์ˆ˜๋Š” ํ•„์š” ์—†์Šต๋‹ˆ๋‹ค.
- ์ ‘๊ทผ์ž ํ•จ์ˆ˜๊ฐ€ ํ•„์š”ํ•œ ๊ฒฝ์šฐ `getVal()` ์ด๋‚˜ `setVal('hello')` ๋ผ๊ณ  ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

  ```javascript
  // bad
  dragon.age();

  // good
  dragon.getAge();

  // bad
  dragon.age(25);

  // good
  dragon.setAge(25);
  ```

- ์†์„ฑ์ด boolean์˜ ๊ฒฝ์šฐ `isVal()` ์ด๋‚˜ `hasVal()` ๋ผ๊ณ  ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
  ```javascript
  // bad
  if (!dragon.age()) {
    return false;
  }

  // good
  if (!dragon.hasAge()) {
    return false;
  }
  ```

- ์ผ๊ด€๋œ๋‹ค๋ฉด `get()` ์ด๋‚˜ `set()` ์ด๋ผ๋Š” ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑํ•ด๋„ ์ข‹์Šต๋‹ˆ๋‹ค.

  ```javascript
  function Jedi(options) {
    options || (options = {});
    var lightsaber = options.lightsaber || 'blue';
    this.set('lightsaber', lightsaber);
  }

  Jedi.prototype.set = function(key, val) {
    this[key] = val;
  };

  Jedi.prototype.get = function(key) {
    return this[key];
  };
  ```

  **[[โฌ†]](#TOC)**


## <a name='constructors'>Constructors</a> [์›๋ฌธ](https://github.com/airbnb/javascript#constructors)

- ์ƒˆ Object์—์„œ ํ”„๋กœํ† ํƒ€์ž…์„ ์žฌ์ •์˜ํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ, ํ”„๋กœํ† ํƒ€์ž… ๊ฐ์ฒด์— ๋ฉ”์„œ๋“œ๋ฅผ ์ถ”๊ฐ€ํ•ด ์ฃผ์‹ญ์‹œ์˜ค. ํ”„๋กœํ† ํƒ€์ž…์„ ์žฌ์ •์˜ํ•˜๋ฉด ์ƒ์†์ด ๋ถˆ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ํ”„๋กœํ† ํƒ€์ž…์„ ๋ฆฌ์…‹ํ•˜๋Š”๊ฒƒ์œผ๋กœ ๋ฒ ์ด์Šค ํด๋ž˜์Šค๋ฅผ ์žฌ์ •์˜ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  ```javascript
  function Jedi() {
    console.log('new jedi');
  }

  // bad
  Jedi.prototype = {
    fight: function fight() {
      console.log('fighting');
    },

    block: function block() {
      console.log('blocking');
    }
  };

  // good
  Jedi.prototype.fight = function fight() {
    console.log('fighting');
  };

  Jedi.prototype.block = function block() {
    console.log('blocking');
  };
  ```

- ๋ฉ”์†Œ๋“œ์˜ ๋ฐ˜ํ™˜ ๊ฐ’์œผ๋กœ `this`๋ฅผ ๋ฐ˜ํ™˜ํ•จ์œผ๋กœ์จ ๋ฉ”์†Œ๋“œ ์ฒด์ธ์„ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  ```javascript
  // bad
  Jedi.prototype.jump = function() {
    this.jumping = true;
    return true;
  };

  Jedi.prototype.setHeight = function(height) {
    this.height = height;
  };

  var luke = new Jedi();
  luke.jump(); // => true
  luke.setHeight(20) // => undefined

  // good
  Jedi.prototype.jump = function() {
    this.jumping = true;
    return this;
  };

  Jedi.prototype.setHeight = function(height) {
    this.height = height;
    return this;
  };

  var luke = new Jedi();

  luke.jump()
    .setHeight(20);
  ```


- ๋…์ž์ ์ธ toString()์„ ๋งŒ๋“ค ์ˆ˜๋„ ์žˆ์ง€๋งŒ ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ์ž‘๋™ํ•˜๋Š”์ง€, ๋ถ€์ž‘์šฉ์ด ์—†๋Š” ๊ฒƒ๋งŒ์€ ํ™•์ธํ•ด ์ฃผ์‹ญ์‹œ์˜ค.

  ```javascript
  function Jedi(options) {
    options || (options = {});
    this.name = options.name || 'no name';
  }

  Jedi.prototype.getName = function getName() {
    return this.name;
  };

  Jedi.prototype.toString = function toString() {
    return 'Jedi - ' + this.getName();
  };
  ```

  **[[โฌ†]](#TOC)**

## <a name='events'>Events</a>

- (DOM ์ด๋ฒคํŠธ๋‚˜ Backbone events์™€ ๊ฐ™์€ ๊ณ ์œ ์˜) ์ด๋ฒคํŠธ ํƒ‘์žฌ์ฒด(payloads)์˜ ๊ฐ’์„ ์ „๋‹ฌํ•˜๋Š” ๊ฒฝ์šฐ ์›์‹œ ๊ฐ’(raw value) ๋Œ€์‹  ํ•ด์‹œ ์ธ์ˆ˜(hash)๋ฅผ ์ „๋‹ฌํ•ฉ๋‹ˆ๋‹ค.
์ด๋ ‡๊ฒŒํ•˜๋Š” ๊ฒƒ์œผ๋กœ ๋‚˜์ค‘์— ๊ฐœ๋ฐœ์ž๊ฐ€ ์ด๋ฒคํŠธ์™€ ๊ด€๋ จ๋œ ๋ชจ๋“  ํ•ธ๋“ค๋Ÿฌ๋ฅผ ์ฐพ์•„ ์—…๋ฐ์ดํŠธ ํ•˜์ง€ ์•Š๊ณ  ์ด๋ฒคํŠธ ํƒ‘์žฌ์ฒด(payloads)์— ๊ฐ’์„ ์ถ”๊ฐ€ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ์ด๊ฒƒ ๋Œ€์‹  :

  ```js
  // bad
  $(this).trigger('listingUpdated', listing.id);

  ...

  $(this).on('listingUpdated', function(e, listingId) {
    // do something with listingId
  });
  ```

  ์ด์ชฝ์„ ์„ ํ˜ธํ•ฉ๋‹ˆ๋‹ค.:

  ```js
  // good
  $(this).trigger('listingUpdated', { listingId : listing.id });

  ...

  $(this).on('listingUpdated', function(e, data) {
    // do something with data.listingId
  });
  ```

**[[โฌ†]](#TOC)**

## <a name='modules'>Modules</a> [์›๋ฌธ](https://github.com/airbnb/javascript#modules)

- ๋ชจ๋“ˆ์˜ ์‹œ์ž‘์€ `!` ๋กœ ์‹œ์ž‘ํ•˜์‹ญ์‹œ์˜ค. ์ด๊ฒƒ์€ ๋ฌธ๋ง์— ์„ธ๋ฏธ์ฝœ๋ก ์„ ๋„ฃ๋Š”๊ฒƒ์„ ์žŠ์€ ๋ชจ๋“ˆ์„ ์—ฐ๊ฒฐํ• ๋•Œ ๋Ÿฐํƒ€์ž„ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.
- ํŒŒ์ผ ์ด๋ฆ„์€ camelCase๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ™์€ ์ด๋ฆ„์˜ ํด๋”์— ์ €์žฅํ•ด์ฃผ์‹ญ์‹œ์˜ค. ๋˜ํ•œ ๋‹จ๋…์œผ๋กœ ๊ณต๊ฐœํ•  ๊ฒฝ์šฐ ์ด๋ฆ„์„ ์ผ์น˜์‹œ์ผœ์ฃผ์‹ญ์‹œ์˜ค.
- noConflict() ๋ผ๋Š” ๋ช…์นญ์œผ๋กœ (์ด๋ฆ„์ด ๊ฒน์ณ ๋ฎ์–ด ์จ์ง€๊ธฐ ์ „์˜) ๋ชจ๋“ˆ์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋ฉ”์„œ๋“œ๋ฅผ ์ถ”๊ฐ€ํ•ด์ฃผ์‹ญ์‹œ์˜ค.
- ํ•ญ์ƒ ๋ชจ๋“ˆ์˜ ์‹œ์ž‘ ๋ถ€๋ถ„์—์„œ` 'use strict';`๋ฅผ ์„ ์–ธํ•ด์ฃผ์‹ญ์‹œ์˜ค.

  ```javascript
  // fancyInput/fancyInput.js

  !function(global) {
    'use strict';

    var previousFancyInput = global.FancyInput;

    function FancyInput(options) {
      this.options = options || {};
    }

    FancyInput.noConflict = function noConflict() {
      global.FancyInput = previousFancyInput;
      return FancyInput;
    };

    global.FancyInput = FancyInput;
  }(this);
  ```

  **[[โฌ†]](#TOC)**


## <a name='jquery'>jQuery</a> [์›๋ฌธ](https://github.com/airbnb/javascript#jquery)

- jQuery Object์˜ ๋ณ€์ˆ˜ ์•ž์—๋Š” `$`์„ ๋ถ€์—ฌํ•ด ์ฃผ์‹ญ์‹œ์˜ค.

  ```javascript
  // bad
  var sidebar = $('.sidebar');

  // good
  var $sidebar = $('.sidebar');
  ```

- jQuery ์ฟผ๋ฆฌ๊ฒฐ๊ณผ๋ฅผ ์บ์‹œํ•ด์ฃผ์‹ญ์‹œ์˜ค.

  ```javascript
  // bad
  function setSidebar() {
    $('.sidebar').hide();

    // ...stuff...

    $('.sidebar').css({
      'background-color': 'pink'
    });
  }

  // good
  function setSidebar() {
    var $sidebar = $('.sidebar');
    $sidebar.hide();

    // ...stuff...

    $sidebar.css({
      'background-color': 'pink'
    });
  }
  ```

- DOM ๊ฒ€์ƒ‰์€ Cascading `$('.sidebar ul')` ์ด๋‚˜ parent > child `$('.sidebar > ul')` ๋ฅผ ์‚ฌ์šฉํ•ด์ฃผ์‹ญ์‹œ์˜ค. [jsPerf](http://jsperf.com/jquery-find-vs-context-sel/16)
- jQuery Object ๊ฒ€์ƒ‰์€ ์Šค์ฝ”ํ”„๊ฐ€ ๋ถ™์€ `find`๋ฅผ ์‚ฌ์šฉํ•ด์ฃผ์‹ญ์‹œ์˜ค.

  ```javascript
  // bad
  $('ul', '.sidebar').hide();

  // bad
  $('.sidebar').find('ul').hide();

  // good
  $('.sidebar ul').hide();

  // good
  $('.sidebar > ul').hide();

  // good
  $sidebar.find('ul');
  ```

  **[[โฌ†]](#TOC)**


## <a name='es5'>ECMAScript 5 Compatibility</a> [์›๋ฌธ](https://github.com/airbnb/javascript#es5)

- [Kangax](https://twitter.com/kangax/)์˜ ES5 [compatibility table](http://kangax.github.com/es5-compat-table/)๋ฅผ ์ฐธ์กฐํ•ด ์ฃผ์‹ญ์‹œ์˜ค.

**[[โฌ†]](#TOC)**


## <a name='testing'>Testing</a> [์›๋ฌธ](https://github.com/airbnb/javascript#testing)

- **๋„ค!(Yup.)**

  ```javascript
  function() {
    return true;
  }
  ```

  **[[โฌ†]](#TOC)**


## <a name='performance'>Performance</a> [์›๋ฌธ](https://github.com/airbnb/javascript#performance)

- [On Layout & Web Performance](http://kellegous.com/j/2013/01/26/layout-performance/)
- [String vs Array Concat](http://jsperf.com/string-vs-array-concat/2)
- [Try/Catch Cost In a Loop](http://jsperf.com/try-catch-in-loop-cost)
- [Bang Function](http://jsperf.com/bang-function)
- [jQuery Find vs Context, Selector](http://jsperf.com/jquery-find-vs-context-sel/13)
- [innerHTML vs textContent for script text](http://jsperf.com/innerhtml-vs-textcontent-for-script-text)
- [Long String Concatenation](http://jsperf.com/ya-string-concat)
- Loading...

**[[โฌ†]](#TOC)**


## <a name='resources'>Resources</a> [์›๋ฌธ](https://github.com/airbnb/javascript#resources)


**Read This**

- [Annotated ECMAScript 5.1](http://es5.github.com/)

**Other Styleguides**

- [Google JavaScript Style Guide](http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml)
- [jQuery Core Style Guidelines](http://docs.jquery.com/JQuery_Core_Style_Guidelines)
- [Principles of Writing Consistent, Idiomatic JavaScript](https://github.com/rwldrn/idiomatic.js/)

**Other Styles**

- [Naming this in nested functions](https://gist.github.com/4135065) - Christian Johansen
- [Conditional Callbacks](https://github.com/airbnb/javascript/issues/52)
- [Popular JavaScript Coding Conventions on Github](http://sideeffect.kr/popularconvention/#javascript)

**Further Reading**

- [Understanding JavaScript Closures](http://javascriptweblog.wordpress.com/2010/10/25/understanding-javascript-closures/) - Angus Croll
- [Basic JavaScript for the impatient programmer](http://www.2ality.com/2013/06/basic-javascript.html) - Dr. Axel Rauschmayer

**Books**

- [JavaScript: The Good Parts](http://www.amazon.com/JavaScript-Good-Parts-Douglas-Crockford/dp/0596517742) - Douglas Crockford
- [JavaScript Patterns](http://www.amazon.com/JavaScript-Patterns-Stoyan-Stefanov/dp/0596806752) - Stoyan Stefanov
- [Pro JavaScript Design Patterns](http://www.amazon.com/JavaScript-Design-Patterns-Recipes-Problem-Solution/dp/159059908X)  - Ross Harmes and Dustin Diaz
- [High Performance Web Sites: Essential Knowledge for Front-End Engineers](http://www.amazon.com/High-Performance-Web-Sites-Essential/dp/0596529309) - Steve Souders
- [Maintainable JavaScript](http://www.amazon.com/Maintainable-JavaScript-Nicholas-C-Zakas/dp/1449327680) - Nicholas C. Zakas
- [JavaScript Web Applications](http://www.amazon.com/JavaScript-Web-Applications-Alex-MacCaw/dp/144930351X) - Alex MacCaw
- [Pro JavaScript Techniques](http://www.amazon.com/Pro-JavaScript-Techniques-John-Resig/dp/1590597273) - John Resig
- [Smashing Node.js: JavaScript Everywhere](http://www.amazon.com/Smashing-Node-js-JavaScript-Everywhere-Magazine/dp/1119962595) - Guillermo Rauch
- [Secrets of the JavaScript Ninja](http://www.amazon.com/Secrets-JavaScript-Ninja-John-Resig/dp/193398869X) - John Resig and Bear Bibeault
- [Human JavaScript](http://humanjavascript.com/) - Henrik Joreteg
- [Superhero.js](http://superherojs.com/) - Kim Joar Bekkelund, Mads Mobรฆk, & Olav Bjorkoy
- [JSBooks](http://jsbooks.revolunet.com/)

**Blogs**

- [DailyJS](http://dailyjs.com/)
- [JavaScript Weekly](http://javascriptweekly.com/)
- [JavaScript, JavaScript...](http://javascriptweblog.wordpress.com/)
- [Bocoup Weblog](http://weblog.bocoup.com/)
- [Adequately Good](http://www.adequatelygood.com/)
- [NCZOnline](http://www.nczonline.net/)
- [Perfection Kills](http://perfectionkills.com/)
- [Ben Alman](http://benalman.com/)
- [Dmitry Baranovskiy](http://dmitry.baranovskiy.com/)
- [Dustin Diaz](http://dustindiaz.com/)
- [nettuts](http://net.tutsplus.com/?s=javascript)

**[[โฌ†]](#TOC)**

## <a name='in-the-wild'>In the Wild</a>

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.

- **Aan Zee**: [AanZee/javascript](https://github.com/AanZee/javascript)
- **Airbnb**: [airbnb/javascript](https://github.com/airbnb/javascript)
- **American Insitutes for Research**: [AIRAST/javascript](https://github.com/AIRAST/javascript)
- **Compass Learning**: [compasslearning/javascript-style-guide](https://github.com/compasslearning/javascript-style-guide)
- **ExactTarget**: [ExactTarget/javascript](https://github.com/ExactTarget/javascript)
- **GeneralElectric**: [GeneralElectric/javascript](https://github.com/GeneralElectric/javascript)
- **GoodData**: [gooddata/gdc-js-style](https://github.com/gooddata/gdc-js-style)
- **Grooveshark**: [grooveshark/javascript](https://github.com/grooveshark/javascript)
- **How About We**: [howaboutwe/javascript](https://github.com/howaboutwe/javascript)
- **Mighty Spring**: [mightyspring/javascript](https://github.com/mightyspring/javascript)
- **MinnPost**: [MinnPost/javascript](https://github.com/MinnPost/javascript)
- **ModCloth**: [modcloth/javascript](https://github.com/modcloth/javascript)
- **National Geographic**: [natgeo/javascript](https://github.com/natgeo/javascript)
- **National Park Service**: [nationalparkservice/javascript](https://github.com/nationalparkservice/javascript)
- **Razorfish**: [razorfish/javascript-style-guide](https://github.com/razorfish/javascript-style-guide)
- **Shutterfly**: [shutterfly/javascript](https://github.com/shutterfly/javascript)
- **Userify**: [userify/javascript](https://github.com/userify/javascript)
- **Zillow**: [zillow/javascript](https://github.com/zillow/javascript)
- **ZocDoc**: [ZocDoc/javascript](https://github.com/ZocDoc/javascript)

## <a name='translation'>Translation</a>

This style guide is also available in other languages:

- :de: **German**: [timofurrer/javascript-style-guide](https://github.com/timofurrer/javascript-style-guide)
- :jp: **Japanese**: [mitsuruog/javacript-style-guide](https://github.com/mitsuruog/javacript-style-guide)
- :br: **Portuguese**: [armoucar/javascript-style-guide](https://github.com/armoucar/javascript-style-guide)
- :cn: **Chinese**: [adamlu/javascript-style-guide](https://github.com/adamlu/javascript-style-guide)
- :es: **Spanish**: [paolocarrasco/javascript-style-guide](https://github.com/paolocarrasco/javascript-style-guide)
- :kr: **Korean**: [tipjs/javascript-style-guide](https://github.com/tipjs/javascript-style-guide)

## <a name='guide-guide'>The JavaScript Style Guide Guide</a>

- [Reference](https://github.com/airbnb/javascript/wiki/The-JavaScript-Style-Guide-Guide)

## <a name='authors'>Contributors</a>

- [View Contributors](https://github.com/airbnb/javascript/graphs/contributors)


## <a name='license'>License</a>

(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.

**[[โฌ†]](#TOC)**

# };

About

JavaScript Style Guide KOREAN

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0