├── es5.md
└── README.md
/es5.md:
--------------------------------------------------------------------------------
1 | [원문:https://github.com/airbnb/javascript](https://github.com/airbnb/javascript)
2 |
3 | # Airbnb JavaScript 스타일 가이드() {
4 |
5 |
6 | ## 목차
7 |
8 | 1. [Types](#types)
9 | 1. [Objects](#objects)
10 | 1. [Arrays](#arrays)
11 | 1. [Strings](#strings)
12 | 1. [Functions](#functions)
13 | 1. [Properties](#properties)
14 | 1. [Variables](#variables)
15 | 1. [Hoisting](#hoisting)
16 | 1. [Conditional Expressions & Equality](#conditionals)
17 | 1. [Blocks](#blocks)
18 | 1. [Comments](#comments)
19 | 1. [Whitespace](#whitespace)
20 | 1. [Commas](#commas)
21 | 1. [Semicolons](#semicolons)
22 | 1. [Type Casting & Coercion](#type-coercion)
23 | 1. [Naming Conventions](#naming-conventions)
24 | 1. [Accessors](#accessors)
25 | 1. [Constructors](#constructors)
26 | 1. [Events](#events)
27 | 1. [Modules](#modules)
28 | 1. [jQuery](#jquery)
29 | 1. [ES5 Compatibility](#es5)
30 | 1. [Testing](#testing)
31 | 1. [Performance](#performance)
32 | 1. [Resources](#resources)
33 | 1. [In the Wild](#in-the-wild)
34 | 1. [Translation](#translation)
35 | 1. [The JavaScript Style Guide Guide](#guide-guide)
36 | 1. [Contributors](#contributors)
37 | 1. [License](#license)
38 |
39 | ## Types [원문](https://github.com/airbnb/javascript#types)
40 |
41 | - **Primitives**: primitive type은 그 값을 직접 조작합니다.
42 |
43 | + `string`
44 | + `number`
45 | + `boolean`
46 | + `null`
47 | + `undefined`
48 |
49 | ```javascript
50 | var foo = 1,
51 | bar = foo;
52 |
53 | bar = 9;
54 |
55 | console.log(foo, bar); // => 1, 9
56 | ```
57 | - **Complex**: 참조형(Complex)은 참조를 통해 값을 조작합니다.
58 |
59 | + `object`
60 | + `array`
61 | + `function`
62 |
63 | ```javascript
64 | var foo = [1, 2],
65 | bar = foo;
66 |
67 | bar[0] = 9;
68 |
69 | console.log(foo[0], bar[0]); // => 9, 9
70 | ```
71 |
72 | **[[↑]](#TOC)**
73 |
74 | ## Objects [원문](https://github.com/airbnb/javascript#objects)
75 |
76 | - Object를 만들 때는 리터럴 구문을 사용하십시오.
77 |
78 | ```javascript
79 | // bad
80 | var item = new Object();
81 |
82 | // good
83 | var item = {};
84 | ```
85 |
86 | - [예약어(reserved words)](http://es5.github.io/#x7.6.1)를 키로 사용하지 마십시오. 이것은 IE8에서 동작하지 않습니다. [More info](https://github.com/airbnb/javascript/issues/61)
87 |
88 | ```javascript
89 | // bad
90 | var superman = {
91 | default: { clark: 'kent' },
92 | private: true
93 | };
94 |
95 | // good
96 | var superman = {
97 | defaults: { clark: 'kent' },
98 | hidden: true
99 | };
100 | ```
101 |
102 | - 예약어 대신 알기 쉬운 동의어(readable synonyms)를 사용하십시오.
103 |
104 | ```javascript
105 | // bad
106 | var superman = {
107 | class: 'alien'
108 | };
109 |
110 | // bad
111 | var superman = {
112 | klass: 'alien'
113 | };
114 |
115 | // good
116 | var superman = {
117 | type: 'alien'
118 | };
119 |
120 | ```
121 | **[[↑]](#TOC)**
122 |
123 | ## Arrays [원문](https://github.com/airbnb/javascript#arrays)
124 |
125 | - 배열을 만들 때 리터럴 구문을 사용하십시오.
126 |
127 | ```javascript
128 | // bad
129 | var items = new Array();
130 |
131 | // good
132 | var items = [];
133 | ```
134 |
135 | - 길이를 알 수없는 경우는 Array#push를 사용하십시오.
136 |
137 | ```javascript
138 | var someStack = [];
139 |
140 |
141 | // bad
142 | someStack[someStack.length] = 'abracadabra';
143 |
144 | // good
145 | someStack.push('abracadabra');
146 | ```
147 |
148 | - 배열을 복사 할 필요가있는 경우 Array#slice를 사용하십시오. [jsPerf](http://jsperf.com/converting-arguments-to-an-array/7)
149 |
150 | ```javascript
151 | var len = items.length,
152 | itemsCopy = [],
153 | i;
154 |
155 | // bad
156 | for (i = 0; i < len; i++) {
157 | itemsCopy[i] = items[i];
158 | }
159 |
160 | // good
161 | itemsCopy = items.slice();
162 | ```
163 |
164 | - Array와 비슷한(Array-Like)한 Object를 Array에 변환하는 경우는 Array#slice를 사용하십시오.
165 |
166 | ```javascript
167 | function trigger() {
168 | var args = Array.prototype.slice.call(arguments);
169 | ...
170 | }
171 | ```
172 |
173 | **[[↑]](#TOC)**
174 |
175 |
176 | ## Strings [원문](https://github.com/airbnb/javascript#strings)
177 |
178 | - 문자열은 작은 따옴표`''`를 사용하십시오.
179 |
180 | ```javascript
181 | // bad
182 | var name = "Bob Parr";
183 |
184 | // good
185 | var name = 'Bob Parr';
186 |
187 | // bad
188 | var fullName = "Bob " + this.lastName;
189 |
190 | // good
191 | var fullName = 'Bob ' + this.lastName;
192 | ```
193 |
194 | - 80 문자 이상의 문자열은 문자열 연결을 사용하여 여러 줄에 걸쳐 기술 할 필요가 있습니다.
195 | - Note : 문자열 연결을 많이하면 성능에 영향을 줄 수 있습니다. [jsPerf](http://jsperf.com/ya-string-concat) & [Discussion](https://github.com/airbnb/javascript/issues/40)
196 |
197 | ```javascript
198 | // bad
199 | 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.';
200 |
201 | // bad
202 | var errorMessage = 'This is a super long error that \
203 | was thrown because of Batman. \
204 | When you stop to think about \
205 | how Batman had anything to do \
206 | with this, you would get nowhere \
207 | fast.';
208 |
209 |
210 | // good
211 | var errorMessage = 'This is a super long error that ' +
212 | 'was thrown because of Batman.' +
213 | 'When you stop to think about ' +
214 | 'how Batman had anything to do ' +
215 | 'with this, you would get nowhere ' +
216 | 'fast.';
217 | ```
218 |
219 | - 프로그램에서 문자열을 생성 할 필요가 있는 경우 (특히 IE는) 문자열 연결 대신 Array#join을 사용하십시오. [jsPerf](http://jsperf.com/string-vs-array-concat/2).
220 |
221 | ```javascript
222 | var items,
223 | messages,
224 | length,
225 | i;
226 |
227 | messages = [{
228 | state: 'success',
229 | message: 'This one worked.'
230 | },{
231 | state: 'success',
232 | message: 'This one worked as well.'
233 | },{
234 | state: 'error',
235 | message: 'This one did not work.'
236 | }];
237 |
238 | length = messages.length;
239 |
240 | // bad
241 | function inbox(messages) {
242 | items = '
';
243 |
244 | for (i = 0; i < length; i++) {
245 | items += '- ' + messages[i].message + '
';
246 | }
247 |
248 | return items + '
';
249 | }
250 |
251 | // good
252 | function inbox(messages) {
253 | items = [];
254 |
255 | for (i = 0; i < length; i++) {
256 | items[i] = messages[i].message;
257 | }
258 |
259 | return '';
260 | }
261 | ```
262 |
263 | **[[↑]](#TOC)**
264 |
265 |
266 | ## Functions [원문](https://github.com/airbnb/javascript#functions)
267 |
268 | - 함수식(Function expressions)
269 |
270 | ```javascript
271 | // 익명함수식(anonymous function expression)
272 | var anonymous = function() {
273 | return true;
274 | };
275 |
276 | // 명명된 함수식(named function expression)
277 | var named = function named() {
278 | return true;
279 | };
280 |
281 | // 즉시실행 함수식(immediately-invoked function expression (IIFE))
282 | (function() {
283 | console.log('Welcome to the Internet. Please follow me.');
284 | })();
285 | ```
286 |
287 | - (if 및 while 등) 블록 내에서 변수에 함수를 할당하는 대신 함수를 선언하지 마십시오. 브라우저는 허용하지만 (마치 'bad news bears'처럼) 모두 다른 방식으로 해석됩니다.
288 | - **Note:** ECMA-262에서는`block`은 statements의 목록에 정의되어 있습니다 만, 함수 선언은 statements가 없습니다. [이 문제는 ECMA-262의 설명을 참조하십시오. ](http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf#page=97).
289 |
290 | ```javascript
291 | // bad
292 | if (currentUser) {
293 | function test() {
294 | console.log('Nope.');
295 | }
296 | }
297 |
298 | // good
299 | var test;
300 | if (currentUser) {
301 | test = function test() {
302 | console.log('Yup.');
303 | };
304 | }
305 | ```
306 |
307 | - 매개 변수(parameter)에 `arguments`를 절대 지정하지 마십시오. 이것은 함수 범위로 전달 될`arguments`객체의 참조를 덮어 쓸 것입니다.
308 |
309 | ```javascript
310 | // bad
311 | function nope(name, options, arguments) {
312 | // ...stuff...
313 | }
314 |
315 | // good
316 | function yup(name, options, args) {
317 | // ...stuff...
318 | }
319 | ```
320 |
321 | **[[↑]](#TOC)**
322 |
323 |
324 |
325 | ## Properties [원문](https://github.com/airbnb/javascript#properties)
326 |
327 | - 속성에 액세스하려면 도트`.`를 사용하십시오.
328 |
329 | ```javascript
330 | var luke = {
331 | jedi: true,
332 | age: 28
333 | };
334 |
335 | // bad
336 | var isJedi = luke['jedi'];
337 |
338 | // good
339 | var isJedi = luke.jedi;
340 | ```
341 |
342 | - 변수를 사용하여 속성에 접근하려면 대괄호`[]`을 사용하십시오.
343 |
344 | ```javascript
345 | var luke = {
346 | jedi: true,
347 | age: 28
348 | };
349 |
350 | function getProp(prop) {
351 | return luke[prop];
352 | }
353 |
354 | var isJedi = getProp('jedi');
355 | ```
356 |
357 | **[[↑]](#TOC)**
358 |
359 |
360 | ## Variables [원문](https://github.com/airbnb/javascript#variables)
361 |
362 | - 변수를 선언 할 때는 항상 `var`를 사용하십시오. 그렇지 않으면 전역 변수로 선언됩니다. 전역 네임 스페이스를 오염시키지 않도록 Captain Planet도 경고하고 있습니다.
363 |
364 | ```javascript
365 | // bad
366 | superPower = new SuperPower();
367 |
368 | // good
369 | var superPower = new SuperPower();
370 | ```
371 |
372 | - 여러 변수를 선언하려면 하나의 `var`를 사용하여 변수마다 줄바꿈하여 선언하십시오.
373 |
374 | ```javascript
375 | // bad
376 | var items = getItems();
377 | var goSportsTeam = true;
378 | var dragonball = 'z';
379 |
380 | // good
381 | var items = getItems(),
382 | goSportsTeam = true,
383 | dragonball = 'z';
384 | ```
385 |
386 | - 정의되지 않은 변수를 마지막으로 선언하십시오. 이것은 나중에 이미 할당된 변수 중 하나를 지정해야하는 경우에 유용합니다.
387 |
388 | ```javascript
389 | // bad
390 | var i, len, dragonball,
391 | items = getItems(),
392 | goSportsTeam = true;
393 |
394 | // bad
395 | var i, items = getItems(),
396 | dragonball,
397 | goSportsTeam = true,
398 | len;
399 |
400 | // good
401 | var items = getItems(),
402 | goSportsTeam = true,
403 | dragonball,
404 | length,
405 | i;
406 | ```
407 |
408 | - 변수의 할당은 스코프의 시작 부분에서 해주십시오. 이것은 변수 선언과 Hoisting 관련 문제를 해결합니다.
409 |
410 | ```javascript
411 | // bad
412 | function() {
413 | test();
414 | console.log('doing stuff..');
415 |
416 | //..other stuff..
417 |
418 | var name = getName();
419 |
420 | if (name === 'test') {
421 | return false;
422 | }
423 |
424 | return name;
425 | }
426 |
427 | // good
428 | function() {
429 | var name = getName();
430 |
431 | test();
432 | console.log('doing stuff..');
433 |
434 | //..other stuff..
435 |
436 | if (name === 'test') {
437 | return false;
438 | }
439 |
440 | return name;
441 | }
442 |
443 | // bad
444 | function() {
445 | var name = getName();
446 |
447 | if (!arguments.length) {
448 | return false;
449 | }
450 |
451 | return true;
452 | }
453 |
454 | // good
455 | function() {
456 | if (!arguments.length) {
457 | return false;
458 | }
459 |
460 | var name = getName();
461 |
462 | return true;
463 | }
464 | ```
465 |
466 | **[[↑]](#TOC)**
467 |
468 |
469 | ## Hoisting [원문](https://github.com/airbnb/javascript#hoisting)
470 |
471 | - 해당 스코프의 시작 부분에 Hoist된 변수선언은 할당되지 않습니다.
472 |
473 | ```javascript
474 | // (notDefined가 전역 변수에 존재하지 않는다고 가정했을 경우)
475 | // 이것은 동작하지 않습니다.
476 | function example() {
477 | console.log(notDefined); // => throws a ReferenceError
478 | }
479 |
480 | // 그 변수를 참조하는 코드 후에 그 변수를 선언 한 경우
481 | // 변수가 Hoist된 상태에서 작동합니다.
482 | // Note : `true`라는 값 자체는 Hoist되지 않습니다.
483 | function example() {
484 | console.log(declaredButNotAssigned); // => undefined
485 | var declaredButNotAssigned = true;
486 | }
487 |
488 | // 인터 프린터는 변수 선언을 스코프의 시작 부분에 Hoist합니다.
489 | // 위의 예는 다음과 같이 다시 작성할 수 있습니다.
490 | function example() {
491 | var declaredButNotAssigned;
492 | console.log(declaredButNotAssigned); // => undefined
493 | declaredButNotAssigned = true;
494 | }
495 | ```
496 |
497 | - 익명 함수의 경우 함수가 할당되기 전에 변수가 Hoist될 수 있습니다.
498 |
499 | ```javascript
500 | function example() {
501 | console.log(anonymous); // => undefined
502 |
503 | anonymous(); // => TypeError anonymous is not a function
504 |
505 | var anonymous = function() {
506 | console.log('anonymous function expression');
507 | };
508 | }
509 | ```
510 |
511 | - 명명 된 함수의 경우도 마찬가지로 변수가 Hoist될 수 있습니다. 함수 이름과 함수 본체는 Hoist되지 않습니다.
512 |
513 | ```javascript
514 | function example() {
515 | console.log(named); // => undefined
516 |
517 | named(); // => TypeError named is not a function
518 |
519 | superPower(); // => ReferenceError superPower is not defined
520 |
521 | var named = function superPower() {
522 | console.log('Flying');
523 | };
524 | }
525 |
526 | // 함수이름과 변수이름이 같은 경우에도 같은 일이 일어납니다.
527 | function example() {
528 | console.log(named); // => undefined
529 |
530 | named(); // => TypeError named is not a function
531 |
532 | var named = function named() {
533 | console.log('named');
534 | }
535 | }
536 | ```
537 |
538 | - 함수 선언은 함수이름과 함수본문이 Hoist됩니다.
539 |
540 | ```javascript
541 | function example() {
542 | superPower(); // => Flying
543 |
544 | function superPower() {
545 | console.log('Flying');
546 | }
547 | }
548 | ```
549 |
550 | - 더 자세한 정보는 [Ben Cherry](http://www.adequatelygood.com/)의 [JavaScript Scoping & Hoisting](http://www.adequatelygood.com/2010/2/JavaScript-Scoping-and-Hoisting)를 참조하십시오.
551 |
552 | **[[↑]](#TOC)**
553 |
554 |
555 |
556 | ## Conditional Expressions & Equality(조건식과 등가식) [원문](https://github.com/airbnb/javascript#conditionals)
557 |
558 | - `==` 나 `!=` 보다는 `===` 와 `!==` 를 사용해 주십시오
559 | - 조건식은`ToBoolean` 메소드에 의해 엄밀하게 비교됩니다. 항상 이 간단한 규칙에 따라 주십시오.
560 |
561 | + **Objects** 는 **true** 로 평가됩니다.
562 | + **undefined** 는 **false** 로 평가됩니다.
563 | + **null** 는 **false** 로 평가됩니다.
564 | + **Booleans** 는 **boolean형의 값** 으로 평가됩니다.
565 | + **Numbers** 는 **true** 로 평가됩니다. 하지만 **+0, -0, or NaN** 의 경우는 **false** 입니다.
566 | + **Strings** 는 **true** 로 평가됩니다. 하지만 빈문자 `''` 의 경우는 **false** 입니다.
567 |
568 | ```javascript
569 | if ([0]) {
570 | // true
571 | // Array는 Object 이므로 true 로 평가됩니다.
572 | }
573 | ```
574 |
575 | - 짧은형식을 사용하십시오.
576 |
577 | ```javascript
578 | // bad
579 | if (name !== '') {
580 | // ...stuff...
581 | }
582 |
583 | // good
584 | if (name) {
585 | // ...stuff...
586 | }
587 |
588 | // bad
589 | if (collection.length > 0) {
590 | // ...stuff...
591 | }
592 |
593 | // good
594 | if (collection.length) {
595 | // ...stuff...
596 | }
597 | ```
598 |
599 | - 더 자세한 정보는 Angus Croll 의 [Truth Equality and JavaScript](http://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/#more-2108)를 참고해 주십시오.
600 |
601 | **[[↑]](#TOC)**
602 |
603 |
604 | ## Blocks [원문](https://github.com/airbnb/javascript#blocks)
605 |
606 | - 복수행 블록은 중괄호 ({})를 사용하십시오.
607 |
608 | ```javascript
609 | // bad
610 | if (test)
611 | return false;
612 |
613 | // good
614 | if (test) return false;
615 |
616 | // good
617 | if (test) {
618 | return false;
619 | }
620 |
621 | // bad
622 | function() { return false; }
623 |
624 | // good
625 | function() {
626 | return false;
627 | }
628 | ```
629 |
630 | **[[↑]](#TOC)**
631 |
632 |
633 | ## Comments [원문](https://github.com/airbnb/javascript#comments)
634 |
635 | - 복수행의 코멘트는 `/** ... */` 를 사용해 주십시오. 그 안에는 설명과 모든 매개 변수와 반환 값에 대한 형식과 값을 설명합니다.
636 |
637 | ```javascript
638 | // bad
639 | // make() returns a new element
640 | // based on the passed in tag name
641 | //
642 | // @param tag
643 | // @return element
644 | function make(tag) {
645 |
646 | // ...stuff...
647 |
648 | return element;
649 | }
650 |
651 | // good
652 | /**
653 | * make() returns a new element
654 | * based on the passed in tag name
655 | *
656 | * @param tag
657 | * @return element
658 | */
659 | function make(tag) {
660 |
661 | // ...stuff...
662 |
663 | return element;
664 | }
665 | ```
666 |
667 | - 한 줄 주석에는`//`를 사용하십시오. 코멘트를 추가하고 싶은 코드의 상단에 작성하십시오. 또한 주석 앞에 빈 줄을 넣어주십시오.
668 |
669 | ```javascript
670 | // bad
671 | var active = true; // is current tab
672 |
673 | // good
674 | // is current tab
675 | var active = true;
676 |
677 | // bad
678 | function getType() {
679 | console.log('fetching type...');
680 | // set the default type to 'no type'
681 | var type = this._type || 'no type';
682 |
683 | return type;
684 | }
685 |
686 | // good
687 | function getType() {
688 | console.log('fetching type...');
689 |
690 | // set the default type to 'no type'
691 | var type = this._type || 'no type';
692 |
693 | return type;
694 | }
695 | ```
696 |
697 | - 문제를 지적하고 재고를 촉구하거나 문제에 대한 해결책을 제시하는 등 의견의 앞에 `FIXME` 나 `TODO`를 붙이는 것으로 다른 개발자의 빠른 이해를 도울 수 있습니다. 이러한 어떤 액션을 동반한다는 의미에서 일반 코멘트와는 다릅니다. 액션은 `FIXME - 해결책이 필요` 또는 `TODO - 구현이 필요` 입니다.
698 |
699 | - 문제에 대한 코멘트로 `// FIXME :`를 사용하십시오.
700 |
701 | ```javascript
702 | function Calculator() {
703 |
704 | // FIXME: 전역 변수를 사용해서는 안됩니다.
705 | total = 0;
706 |
707 | return this;
708 | }
709 | ```
710 |
711 | - 문제 해결책에 대한 코멘트로 `// TODO :`를 사용하십시오.
712 |
713 | ```javascript
714 | function Calculator() {
715 |
716 | // TODO: total은 옵션 매개 변수로 설정되어야 함.
717 | this.total = 0;
718 | return this;
719 | }
720 | ```
721 |
722 | **[[↑]](#TOC)**
723 |
724 |
725 | ## Whitespace [원문](https://github.com/airbnb/javascript#whitespace)
726 |
727 | - 탭에는 공백 2개를 설정하십시오.
728 |
729 | ```javascript
730 | // bad
731 | function() {
732 | ∙∙∙∙var name;
733 | }
734 |
735 | // bad
736 | function() {
737 | ∙var name;
738 | }
739 |
740 | // good
741 | function() {
742 | ∙∙var name;
743 | }
744 | ```
745 | - 중괄호({})의 앞에 공백을 하나 넣어주십시오.
746 |
747 | ```javascript
748 | // bad
749 | function test(){
750 | console.log('test');
751 | }
752 |
753 | // good
754 | function test() {
755 | console.log('test');
756 | }
757 |
758 | // bad
759 | dog.set('attr',{
760 | age: '1 year',
761 | breed: 'Bernese Mountain Dog'
762 | });
763 |
764 | // good
765 | dog.set('attr', {
766 | age: '1 year',
767 | breed: 'Bernese Mountain Dog'
768 | });
769 | ```
770 | - 파일의 마지막에는 빈 줄을 하나 넣어주십시오.
771 |
772 | ```javascript
773 | // bad
774 | (function(global) {
775 | // ...stuff...
776 | })(this);
777 | ```
778 |
779 | ```javascript
780 | // good
781 | (function(global) {
782 | // ...stuff...
783 | })(this);
784 |
785 | ```
786 |
787 | - 메소드 체인이 길어지는 경우 적절히 들여쓰기(indentation) 하십시오.
788 |
789 | ```javascript
790 | // bad
791 | $('#items').find('.selected').highlight().end().find('.open').updateCount();
792 |
793 | // good
794 | $('#items')
795 | .find('.selected')
796 | .highlight()
797 | .end()
798 | .find('.open')
799 | .updateCount();
800 |
801 | // bad
802 | var leds = stage.selectAll('.led').data(data).enter().append('svg:svg').class('led', true)
803 | .attr('width', (radius + margin) * 2).append('svg:g')
804 | .attr('transform', 'translate(' + (radius + margin) + ',' + (radius + margin) + ')')
805 | .call(tron.led);
806 |
807 | // good
808 | var leds = stage.selectAll('.led')
809 | .data(data)
810 | .enter().append('svg:svg')
811 | .class('led', true)
812 | .attr('width', (radius + margin) * 2)
813 | .append('svg:g')
814 | .attr('transform', 'translate(' + (radius + margin) + ',' + (radius + margin) + ')')
815 | .call(tron.led);
816 | ```
817 |
818 | **[[↑]](#TOC)**
819 |
820 | ## Commas [원문](https://github.com/airbnb/javascript#commas)
821 |
822 | - 선두의 comma는 **하지마십시오.**
823 |
824 | ```javascript
825 | // bad
826 | var once
827 | , upon
828 | , aTime;
829 |
830 | // good
831 | var once,
832 | upon,
833 | aTime;
834 |
835 | // bad
836 | var hero = {
837 | firstName: 'Bob'
838 | , lastName: 'Parr'
839 | , heroName: 'Mr. Incredible'
840 | , superPower: 'strength'
841 | };
842 |
843 | // good
844 | var hero = {
845 | firstName: 'Bob',
846 | lastName: 'Parr',
847 | heroName: 'Mr. Incredible',
848 | superPower: 'strength'
849 | };
850 | ```
851 |
852 | - 말미의 불필요한 쉼표도 **하지 마십시오.** 이것은 IE6/7과 quirksmode의 IE9에서 문제를 일으킬 수 있습니다.
853 | 또한 ES3의 일부 구현에서 불필요한 쉼표가 있는 경우, 배열 길이를 추가합니다.
854 | 이것은 ES5에서 분명해졌습니다.([source](http://es5.github.io/#D)):
855 |
856 | > 제 5 판에서는 말미의 불필요한 쉼표가 있는 ArrayInitialiser (배열 초기화 연산자)라도 배열에 길이를 추가하지 않는다는 사실을 명확히하고 있습니다. 이것은 제 3 판에서 의미적인 변경은 아닙니다만, 일부의 구현은 이전부터 이것을 오해하고 있었을지도 모릅니다.
857 |
858 | ```javascript
859 | // bad
860 | var hero = {
861 | firstName: 'Kevin',
862 | lastName: 'Flynn',
863 | };
864 |
865 | var heroes = [
866 | 'Batman',
867 | 'Superman',
868 | ];
869 |
870 | // good
871 | var hero = {
872 | firstName: 'Kevin',
873 | lastName: 'Flynn'
874 | };
875 |
876 | var heroes = [
877 | 'Batman',
878 | 'Superman'
879 | ];
880 | ```
881 |
882 | **[[↑]](#TOC)**
883 |
884 |
885 | ## Semicolons [원문](https://github.com/airbnb/javascript#semicolons)
886 |
887 | - **네!(Yup.)**
888 |
889 | ```javascript
890 | // bad
891 | (function() {
892 | var name = 'Skywalker'
893 | return name
894 | })()
895 |
896 | // good
897 | (function() {
898 | var name = 'Skywalker';
899 | return name;
900 | })();
901 |
902 | // good
903 | ;(function() {
904 | var name = 'Skywalker';
905 | return name;
906 | })();
907 | ```
908 |
909 | **[[↑]](#TOC)**
910 |
911 |
912 | ## Type Casting & Coercion(강제) [원문](https://github.com/airbnb/javascript#type-coercion)
913 |
914 | - 문의 시작 부분에서 형을 강제합니다.
915 | - Strings:
916 |
917 | ```javascript
918 | // => this.reviewScore = 9;
919 |
920 | // bad
921 | var totalScore = this.reviewScore + '';
922 |
923 | // good
924 | var totalScore = '' + this.reviewScore;
925 |
926 | // bad
927 | var totalScore = '' + this.reviewScore + ' total score';
928 |
929 | // good
930 | var totalScore = this.reviewScore + ' total score';
931 | ```
932 |
933 | - 숫자는`parseInt`를 사용하십시오. 항상 형변환을 위한 기수(radix)를 인수로 전달하십시오.
934 |
935 | ```javascript
936 | var inputValue = '4';
937 |
938 | // bad
939 | var val = new Number(inputValue);
940 |
941 | // bad
942 | var val = +inputValue;
943 |
944 | // bad
945 | var val = inputValue >> 0;
946 |
947 | // bad
948 | var val = parseInt(inputValue);
949 |
950 | // good
951 | var val = Number(inputValue);
952 |
953 | // good
954 | var val = parseInt(inputValue, 10);
955 | ```
956 |
957 | - 어떤 이유에 의해 `parseInt` 가 병목이 되고, [성능적인 이유](http://jsperf.com/coercion-vs-casting/3)로 Bitshift를 사용할 필요가 있을 경우,
958 | 하려고 하는것에 대해, why(왜)와 what(무엇)의 설명을 코멘트로 남겨주십시오.
959 |
960 | ```javascript
961 | // good
962 | /**
963 | * parseInt가 병목을 일으키므로
964 | * Bitshift로 문자열을 수치로 강제적으로 변환하는 방법으로
965 | * 성능을 개선시킵니다.
966 | */
967 | var val = inputValue >> 0;
968 | ```
969 |
970 | - Booleans:
971 |
972 | ```javascript
973 | var age = 0;
974 |
975 | // bad
976 | var hasAge = new Boolean(age);
977 |
978 | // good
979 | var hasAge = Boolean(age);
980 |
981 | // good
982 | var hasAge = !!age;
983 | ```
984 |
985 | **[[↑]](#TOC)**
986 |
987 |
988 | ## Naming Conventions [원문](https://github.com/airbnb/javascript#naming-conventions)
989 |
990 | - 한문자 이름은 피하십시오. 이름에서 의도를 읽을 수 있도록 하십시오.
991 |
992 | ```javascript
993 | // bad
994 | function q() {
995 | // ...stuff...
996 | }
997 |
998 | // good
999 | function query() {
1000 | // ..stuff..
1001 | }
1002 | ```
1003 |
1004 | - Object, 함수, 그리고 인스턴스로는 camelCase를 사용하십시오.
1005 |
1006 | ```javascript
1007 | // bad
1008 | var OBJEcttsssss = {};
1009 | var this_is_my_object = {};
1010 | var this-is-my-object = {};
1011 | function c() {};
1012 | var u = new user({
1013 | name: 'Bob Parr'
1014 | });
1015 |
1016 | // good
1017 | var thisIsMyObject = {};
1018 | function thisIsMyFunction() {};
1019 | var user = new User({
1020 | name: 'Bob Parr'
1021 | });
1022 | ```
1023 |
1024 | - Class와 생성자에는 PascalCase를 사용하십시오.
1025 |
1026 | ```javascript
1027 | // bad
1028 | function user(options) {
1029 | this.name = options.name;
1030 | }
1031 |
1032 | var bad = new user({
1033 | name: 'nope'
1034 | });
1035 |
1036 | // good
1037 | function User(options) {
1038 | this.name = options.name;
1039 | }
1040 |
1041 | var good = new User({
1042 | name: 'yup'
1043 | });
1044 | ```
1045 |
1046 | - private 속성 이름은 밑줄 `_` 을 사용하십시오.
1047 |
1048 | ```javascript
1049 | // bad
1050 | this.__firstName__ = 'Panda';
1051 | this.firstName_ = 'Panda';
1052 |
1053 | // good
1054 | this._firstName = 'Panda';
1055 | ```
1056 |
1057 | - `this`의 참조를 저장할 때 `_this` 를 사용하십시오.
1058 |
1059 | ```javascript
1060 | // bad
1061 | function() {
1062 | var self = this;
1063 | return function() {
1064 | console.log(self);
1065 | };
1066 | }
1067 |
1068 | // bad
1069 | function() {
1070 | var that = this;
1071 | return function() {
1072 | console.log(that);
1073 | };
1074 | }
1075 |
1076 | // good
1077 | function() {
1078 | var _this = this;
1079 | return function() {
1080 | console.log(_this);
1081 | };
1082 | }
1083 | ```
1084 |
1085 | - 함수에 이름을 붙여주십시오. 이것은 stack traces를 추적하기 쉽게하기 때문입니다.
1086 |
1087 | ```javascript
1088 | // bad
1089 | var log = function(msg) {
1090 | console.log(msg);
1091 | };
1092 |
1093 | // good
1094 | var log = function log(msg) {
1095 | console.log(msg);
1096 | };
1097 | ```
1098 |
1099 | **[[↑]](#TOC)**
1100 |
1101 |
1102 | ## Accessors [원문](https://github.com/airbnb/javascript#accessors)
1103 |
1104 | - 속성을 위한 접근자(Accessor) 함수는 필요 없습니다.
1105 | - 접근자 함수가 필요한 경우 `getVal()` 이나 `setVal('hello')` 라고 사용합니다.
1106 |
1107 | ```javascript
1108 | // bad
1109 | dragon.age();
1110 |
1111 | // good
1112 | dragon.getAge();
1113 |
1114 | // bad
1115 | dragon.age(25);
1116 |
1117 | // good
1118 | dragon.setAge(25);
1119 | ```
1120 |
1121 | - 속성이 boolean의 경우 `isVal()` 이나 `hasVal()` 라고 사용합니다.
1122 | ```javascript
1123 | // bad
1124 | if (!dragon.age()) {
1125 | return false;
1126 | }
1127 |
1128 | // good
1129 | if (!dragon.hasAge()) {
1130 | return false;
1131 | }
1132 | ```
1133 |
1134 | - 일관된다면 `get()` 이나 `set()` 이라는 함수를 작성해도 좋습니다.
1135 |
1136 | ```javascript
1137 | function Jedi(options) {
1138 | options || (options = {});
1139 | var lightsaber = options.lightsaber || 'blue';
1140 | this.set('lightsaber', lightsaber);
1141 | }
1142 |
1143 | Jedi.prototype.set = function(key, val) {
1144 | this[key] = val;
1145 | };
1146 |
1147 | Jedi.prototype.get = function(key) {
1148 | return this[key];
1149 | };
1150 | ```
1151 |
1152 | **[[↑]](#TOC)**
1153 |
1154 |
1155 | ## Constructors [원문](https://github.com/airbnb/javascript#constructors)
1156 |
1157 | - 새 Object에서 프로토타입을 재정의하는 것이 아니라, 프로토타입 객체에 메서드를 추가해 주십시오. 프로토타입을 재정의하면 상속이 불가능합니다. 프로토타입을 리셋하는것으로 베이스 클래스를 재정의 할 수 있습니다.
1158 |
1159 | ```javascript
1160 | function Jedi() {
1161 | console.log('new jedi');
1162 | }
1163 |
1164 | // bad
1165 | Jedi.prototype = {
1166 | fight: function fight() {
1167 | console.log('fighting');
1168 | },
1169 |
1170 | block: function block() {
1171 | console.log('blocking');
1172 | }
1173 | };
1174 |
1175 | // good
1176 | Jedi.prototype.fight = function fight() {
1177 | console.log('fighting');
1178 | };
1179 |
1180 | Jedi.prototype.block = function block() {
1181 | console.log('blocking');
1182 | };
1183 | ```
1184 |
1185 | - 메소드의 반환 값으로 `this`를 반환함으로써 메소드 체인을 할 수 있습니다.
1186 |
1187 | ```javascript
1188 | // bad
1189 | Jedi.prototype.jump = function() {
1190 | this.jumping = true;
1191 | return true;
1192 | };
1193 |
1194 | Jedi.prototype.setHeight = function(height) {
1195 | this.height = height;
1196 | };
1197 |
1198 | var luke = new Jedi();
1199 | luke.jump(); // => true
1200 | luke.setHeight(20) // => undefined
1201 |
1202 | // good
1203 | Jedi.prototype.jump = function() {
1204 | this.jumping = true;
1205 | return this;
1206 | };
1207 |
1208 | Jedi.prototype.setHeight = function(height) {
1209 | this.height = height;
1210 | return this;
1211 | };
1212 |
1213 | var luke = new Jedi();
1214 |
1215 | luke.jump()
1216 | .setHeight(20);
1217 | ```
1218 |
1219 |
1220 | - 독자적인 toString()을 만들 수도 있지만 올바르게 작동하는지, 부작용이 없는 것만은 확인해 주십시오.
1221 |
1222 | ```javascript
1223 | function Jedi(options) {
1224 | options || (options = {});
1225 | this.name = options.name || 'no name';
1226 | }
1227 |
1228 | Jedi.prototype.getName = function getName() {
1229 | return this.name;
1230 | };
1231 |
1232 | Jedi.prototype.toString = function toString() {
1233 | return 'Jedi - ' + this.getName();
1234 | };
1235 | ```
1236 |
1237 | **[[↑]](#TOC)**
1238 |
1239 | ## Events
1240 |
1241 | - (DOM 이벤트나 Backbone events와 같은 고유의) 이벤트 탑재체(payloads)의 값을 전달하는 경우 원시 값(raw value) 대신 해시 인수(hash)를 전달합니다.
1242 | 이렇게하는 것으로 나중에 개발자가 이벤트와 관련된 모든 핸들러를 찾아 업데이트 하지 않고 이벤트 탑재체(payloads)에 값을 추가 할 수 있습니다. 예를 들어, 이것 대신 :
1243 |
1244 | ```js
1245 | // bad
1246 | $(this).trigger('listingUpdated', listing.id);
1247 |
1248 | ...
1249 |
1250 | $(this).on('listingUpdated', function(e, listingId) {
1251 | // do something with listingId
1252 | });
1253 | ```
1254 |
1255 | 이쪽을 선호합니다.:
1256 |
1257 | ```js
1258 | // good
1259 | $(this).trigger('listingUpdated', { listingId : listing.id });
1260 |
1261 | ...
1262 |
1263 | $(this).on('listingUpdated', function(e, data) {
1264 | // do something with data.listingId
1265 | });
1266 | ```
1267 |
1268 | **[[↑]](#TOC)**
1269 |
1270 | ## Modules [원문](https://github.com/airbnb/javascript#modules)
1271 |
1272 | - 모듈의 시작은 `!` 로 시작하십시오. 이것은 문말에 세미콜론을 넣는것을 잊은 모듈을 연결할때 런타임 오류가 발생하지 않기 때문입니다.
1273 | - 파일 이름은 camelCase를 사용하여 같은 이름의 폴더에 저장해주십시오. 또한 단독으로 공개할 경우 이름을 일치시켜주십시오.
1274 | - noConflict() 라는 명칭으로 (이름이 겹쳐 덮어 써지기 전의) 모듈을 반환하는 메서드를 추가해주십시오.
1275 | - 항상 모듈의 시작 부분에서` 'use strict';`를 선언해주십시오.
1276 |
1277 | ```javascript
1278 | // fancyInput/fancyInput.js
1279 |
1280 | !function(global) {
1281 | 'use strict';
1282 |
1283 | var previousFancyInput = global.FancyInput;
1284 |
1285 | function FancyInput(options) {
1286 | this.options = options || {};
1287 | }
1288 |
1289 | FancyInput.noConflict = function noConflict() {
1290 | global.FancyInput = previousFancyInput;
1291 | return FancyInput;
1292 | };
1293 |
1294 | global.FancyInput = FancyInput;
1295 | }(this);
1296 | ```
1297 |
1298 | **[[↑]](#TOC)**
1299 |
1300 |
1301 | ## jQuery [원문](https://github.com/airbnb/javascript#jquery)
1302 |
1303 | - jQuery Object의 변수 앞에는 `$`을 부여해 주십시오.
1304 |
1305 | ```javascript
1306 | // bad
1307 | var sidebar = $('.sidebar');
1308 |
1309 | // good
1310 | var $sidebar = $('.sidebar');
1311 | ```
1312 |
1313 | - jQuery 쿼리결과를 캐시해주십시오.
1314 |
1315 | ```javascript
1316 | // bad
1317 | function setSidebar() {
1318 | $('.sidebar').hide();
1319 |
1320 | // ...stuff...
1321 |
1322 | $('.sidebar').css({
1323 | 'background-color': 'pink'
1324 | });
1325 | }
1326 |
1327 | // good
1328 | function setSidebar() {
1329 | var $sidebar = $('.sidebar');
1330 | $sidebar.hide();
1331 |
1332 | // ...stuff...
1333 |
1334 | $sidebar.css({
1335 | 'background-color': 'pink'
1336 | });
1337 | }
1338 | ```
1339 |
1340 | - DOM 검색은 Cascading `$('.sidebar ul')` 이나 parent > child `$('.sidebar > ul')` 를 사용해주십시오. [jsPerf](http://jsperf.com/jquery-find-vs-context-sel/16)
1341 | - jQuery Object 검색은 스코프가 붙은 `find`를 사용해주십시오.
1342 |
1343 | ```javascript
1344 | // bad
1345 | $('ul', '.sidebar').hide();
1346 |
1347 | // bad
1348 | $('.sidebar').find('ul').hide();
1349 |
1350 | // good
1351 | $('.sidebar ul').hide();
1352 |
1353 | // good
1354 | $('.sidebar > ul').hide();
1355 |
1356 | // good
1357 | $sidebar.find('ul');
1358 | ```
1359 |
1360 | **[[↑]](#TOC)**
1361 |
1362 |
1363 | ## ECMAScript 5 Compatibility [원문](https://github.com/airbnb/javascript#es5)
1364 |
1365 | - [Kangax](https://twitter.com/kangax/)의 ES5 [compatibility table](http://kangax.github.com/es5-compat-table/)를 참조해 주십시오.
1366 |
1367 | **[[↑]](#TOC)**
1368 |
1369 |
1370 | ## Testing [원문](https://github.com/airbnb/javascript#testing)
1371 |
1372 | - **네!(Yup.)**
1373 |
1374 | ```javascript
1375 | function() {
1376 | return true;
1377 | }
1378 | ```
1379 |
1380 | **[[↑]](#TOC)**
1381 |
1382 |
1383 | ## Performance [원문](https://github.com/airbnb/javascript#performance)
1384 |
1385 | - [On Layout & Web Performance](http://kellegous.com/j/2013/01/26/layout-performance/)
1386 | - [String vs Array Concat](http://jsperf.com/string-vs-array-concat/2)
1387 | - [Try/Catch Cost In a Loop](http://jsperf.com/try-catch-in-loop-cost)
1388 | - [Bang Function](http://jsperf.com/bang-function)
1389 | - [jQuery Find vs Context, Selector](http://jsperf.com/jquery-find-vs-context-sel/13)
1390 | - [innerHTML vs textContent for script text](http://jsperf.com/innerhtml-vs-textcontent-for-script-text)
1391 | - [Long String Concatenation](http://jsperf.com/ya-string-concat)
1392 | - Loading...
1393 |
1394 | **[[↑]](#TOC)**
1395 |
1396 |
1397 | ## Resources [원문](https://github.com/airbnb/javascript#resources)
1398 |
1399 |
1400 | **Read This**
1401 |
1402 | - [Annotated ECMAScript 5.1](http://es5.github.com/)
1403 |
1404 | **Other Styleguides**
1405 |
1406 | - [Google JavaScript Style Guide](http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml)
1407 | - [jQuery Core Style Guidelines](http://docs.jquery.com/JQuery_Core_Style_Guidelines)
1408 | - [Principles of Writing Consistent, Idiomatic JavaScript](https://github.com/rwldrn/idiomatic.js/)
1409 |
1410 | **Other Styles**
1411 |
1412 | - [Naming this in nested functions](https://gist.github.com/4135065) - Christian Johansen
1413 | - [Conditional Callbacks](https://github.com/airbnb/javascript/issues/52)
1414 | - [Popular JavaScript Coding Conventions on Github](http://sideeffect.kr/popularconvention/#javascript)
1415 |
1416 | **Further Reading**
1417 |
1418 | - [Understanding JavaScript Closures](http://javascriptweblog.wordpress.com/2010/10/25/understanding-javascript-closures/) - Angus Croll
1419 | - [Basic JavaScript for the impatient programmer](http://www.2ality.com/2013/06/basic-javascript.html) - Dr. Axel Rauschmayer
1420 |
1421 | **Books**
1422 |
1423 | - [JavaScript: The Good Parts](http://www.amazon.com/JavaScript-Good-Parts-Douglas-Crockford/dp/0596517742) - Douglas Crockford
1424 | - [JavaScript Patterns](http://www.amazon.com/JavaScript-Patterns-Stoyan-Stefanov/dp/0596806752) - Stoyan Stefanov
1425 | - [Pro JavaScript Design Patterns](http://www.amazon.com/JavaScript-Design-Patterns-Recipes-Problem-Solution/dp/159059908X) - Ross Harmes and Dustin Diaz
1426 | - [High Performance Web Sites: Essential Knowledge for Front-End Engineers](http://www.amazon.com/High-Performance-Web-Sites-Essential/dp/0596529309) - Steve Souders
1427 | - [Maintainable JavaScript](http://www.amazon.com/Maintainable-JavaScript-Nicholas-C-Zakas/dp/1449327680) - Nicholas C. Zakas
1428 | - [JavaScript Web Applications](http://www.amazon.com/JavaScript-Web-Applications-Alex-MacCaw/dp/144930351X) - Alex MacCaw
1429 | - [Pro JavaScript Techniques](http://www.amazon.com/Pro-JavaScript-Techniques-John-Resig/dp/1590597273) - John Resig
1430 | - [Smashing Node.js: JavaScript Everywhere](http://www.amazon.com/Smashing-Node-js-JavaScript-Everywhere-Magazine/dp/1119962595) - Guillermo Rauch
1431 | - [Secrets of the JavaScript Ninja](http://www.amazon.com/Secrets-JavaScript-Ninja-John-Resig/dp/193398869X) - John Resig and Bear Bibeault
1432 | - [Human JavaScript](http://humanjavascript.com/) - Henrik Joreteg
1433 | - [Superhero.js](http://superherojs.com/) - Kim Joar Bekkelund, Mads Mobæk, & Olav Bjorkoy
1434 | - [JSBooks](http://jsbooks.revolunet.com/)
1435 |
1436 | **Blogs**
1437 |
1438 | - [DailyJS](http://dailyjs.com/)
1439 | - [JavaScript Weekly](http://javascriptweekly.com/)
1440 | - [JavaScript, JavaScript...](http://javascriptweblog.wordpress.com/)
1441 | - [Bocoup Weblog](http://weblog.bocoup.com/)
1442 | - [Adequately Good](http://www.adequatelygood.com/)
1443 | - [NCZOnline](http://www.nczonline.net/)
1444 | - [Perfection Kills](http://perfectionkills.com/)
1445 | - [Ben Alman](http://benalman.com/)
1446 | - [Dmitry Baranovskiy](http://dmitry.baranovskiy.com/)
1447 | - [Dustin Diaz](http://dustindiaz.com/)
1448 | - [nettuts](http://net.tutsplus.com/?s=javascript)
1449 |
1450 | **[[↑]](#TOC)**
1451 |
1452 | ## In the Wild
1453 |
1454 | 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.
1455 |
1456 | - **Aan Zee**: [AanZee/javascript](https://github.com/AanZee/javascript)
1457 | - **Airbnb**: [airbnb/javascript](https://github.com/airbnb/javascript)
1458 | - **American Insitutes for Research**: [AIRAST/javascript](https://github.com/AIRAST/javascript)
1459 | - **Compass Learning**: [compasslearning/javascript-style-guide](https://github.com/compasslearning/javascript-style-guide)
1460 | - **ExactTarget**: [ExactTarget/javascript](https://github.com/ExactTarget/javascript)
1461 | - **GeneralElectric**: [GeneralElectric/javascript](https://github.com/GeneralElectric/javascript)
1462 | - **GoodData**: [gooddata/gdc-js-style](https://github.com/gooddata/gdc-js-style)
1463 | - **Grooveshark**: [grooveshark/javascript](https://github.com/grooveshark/javascript)
1464 | - **How About We**: [howaboutwe/javascript](https://github.com/howaboutwe/javascript)
1465 | - **Mighty Spring**: [mightyspring/javascript](https://github.com/mightyspring/javascript)
1466 | - **MinnPost**: [MinnPost/javascript](https://github.com/MinnPost/javascript)
1467 | - **ModCloth**: [modcloth/javascript](https://github.com/modcloth/javascript)
1468 | - **National Geographic**: [natgeo/javascript](https://github.com/natgeo/javascript)
1469 | - **National Park Service**: [nationalparkservice/javascript](https://github.com/nationalparkservice/javascript)
1470 | - **Razorfish**: [razorfish/javascript-style-guide](https://github.com/razorfish/javascript-style-guide)
1471 | - **Shutterfly**: [shutterfly/javascript](https://github.com/shutterfly/javascript)
1472 | - **Userify**: [userify/javascript](https://github.com/userify/javascript)
1473 | - **Zillow**: [zillow/javascript](https://github.com/zillow/javascript)
1474 | - **ZocDoc**: [ZocDoc/javascript](https://github.com/ZocDoc/javascript)
1475 |
1476 | ## Translation
1477 |
1478 | This style guide is also available in other languages:
1479 |
1480 | - :de: **German**: [timofurrer/javascript-style-guide](https://github.com/timofurrer/javascript-style-guide)
1481 | - :jp: **Japanese**: [mitsuruog/javacript-style-guide](https://github.com/mitsuruog/javacript-style-guide)
1482 | - :br: **Portuguese**: [armoucar/javascript-style-guide](https://github.com/armoucar/javascript-style-guide)
1483 | - :cn: **Chinese**: [adamlu/javascript-style-guide](https://github.com/adamlu/javascript-style-guide)
1484 | - :es: **Spanish**: [paolocarrasco/javascript-style-guide](https://github.com/paolocarrasco/javascript-style-guide)
1485 | - :kr: **Korean**: [tipjs/javascript-style-guide](https://github.com/tipjs/javascript-style-guide)
1486 |
1487 | ## The JavaScript Style Guide Guide
1488 |
1489 | - [Reference](https://github.com/airbnb/javascript/wiki/The-JavaScript-Style-Guide-Guide)
1490 |
1491 | ## Contributors
1492 |
1493 | - [View Contributors](https://github.com/airbnb/javascript/graphs/contributors)
1494 |
1495 |
1496 | ## License
1497 |
1498 | (The MIT License)
1499 |
1500 | Copyright (c) 2012 Airbnb
1501 |
1502 | Permission is hereby granted, free of charge, to any person obtaining
1503 | a copy of this software and associated documentation files (the
1504 | 'Software'), to deal in the Software without restriction, including
1505 | without limitation the rights to use, copy, modify, merge, publish,
1506 | distribute, sublicense, and/or sell copies of the Software, and to
1507 | permit persons to whom the Software is furnished to do so, subject to
1508 | the following conditions:
1509 |
1510 | The above copyright notice and this permission notice shall be
1511 | included in all copies or substantial portions of the Software.
1512 |
1513 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
1514 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1515 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
1516 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
1517 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
1518 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
1519 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1520 |
1521 | **[[↑]](#TOC)**
1522 |
1523 | # };
1524 |
1525 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | [원문:https://github.com/airbnb/javascript](https://github.com/airbnb/javascript)
3 |
4 | # Airbnb JavaScript 스타일 가이드() {
5 |
6 | *JavaScript에 대한 대부분 합리적인 접근 방법*
7 |
8 | 다른 스타일 가이드들
9 | - [ES5](https://github.com/tipjs/javascript-style-guide/blob/master/es5.md)
10 | - [React](https://github.com/airbnb/javascript/tree/master/react)
11 | - [CSS & Sass](https://github.com/airbnb/css)
12 | - [Ruby](https://github.com/airbnb/ruby)
13 |
14 | ## 목차
15 |
16 | 1. [형(Types)](#형types)
17 | 1. [참조(References)](#참조references)
18 | 1. [오브젝트(Objects)](#오브젝트objects)
19 | 1. [배열(Arrays)](#배열arrays)
20 | 1. [구조화대입(Destructuring)](#구조화대입destructuring)
21 | 1. [문자열(Strings)](#문자열strings)
22 | 1. [함수(Functions)](#함수functions)
23 | 1. [Arrow함수(Arrow Functions)](#arrow함수arrow-functions)
24 | 1. [Classes & Constructors](#classes--constructors)
25 | 1. [모듈(Modules)](#모듈modules)
26 | 1. [이터레이터와 제너레이터(Iterators and Generators)](#이터레이터와-제너레이터iterators-and-generators)
27 | 1. [프로퍼티(Properties)](#프로퍼티properties)
28 | 1. [변수(Variables)](#변수variables)
29 | 1. [Hoisting](#hoisting)
30 | 1. [조건식과 등가식(Comparison Operators & Equality)](#조건식과-등가식comparison-operators--equality)
31 | 1. [블록(Blocks)](#블록blocks)
32 | 1. [코멘트(Comments)](#코멘트comments)
33 | 1. [공백(Whitespace)](#공백whitespace)
34 | 1. [콤마(Commas)](#콤마commas)
35 | 1. [세미콜론(Semicolons)](#세미콜론semicolons)
36 | 1. [형변환과 강제(Type Casting & Coercion)](#형변환과-강제type-casting--coercion)
37 | 1. [명명규칙(Naming Conventions)](#명명규칙naming-conventions)
38 | 1. [억세서(Accessors)](#억세서accessors)
39 | 1. [이벤트(Events)](#이벤트events)
40 | 1. [jQuery](#jquery)
41 | 1. [ECMAScript 5 Compatibility](#ecmascript-5-compatibility)
42 | 1. [ECMAScript 6 Styles](#ecmascript-6-styles)
43 | 1. [Testing](#testing)
44 | 1. [Performance](#performance)
45 | 1. [Resources](#resources)
46 | 1. [In the Wild](#in-the-wild)
47 | 1. [Translation](#translation)
48 | 1. [The JavaScript Style Guide Guide](#the-javascript-style-guide-guide)
49 | 1. [Chat With Us About JavaScript](#chat-with-us-about-javascript)
50 | 1. [Contributors](#contributors)
51 | 1. [License](#license)
52 |
53 | ## 형(Types)
54 |
55 | - [1.1](#1.1) **Primitives**: When you access a primitive type you work directly on its value.
56 | - [1.1](#1.1) **Primitives**: primitive type은 그 값을 직접 조작합니다.
57 | + `string`
58 | + `number`
59 | + `boolean`
60 | + `null`
61 | + `undefined`
62 |
63 | ```javascript
64 | const foo = 1;
65 | let bar = foo;
66 |
67 | bar = 9;
68 |
69 | console.log(foo, bar); // => 1, 9
70 | ```
71 | - [1.2](#1.2) **Complex**: When you access a complex type you work on a reference to its value.
72 | - [1.2](#1.2) **참조형**: 참조형(Complex)은 참조를 통해 값을 조작합니다.
73 |
74 | + `object`
75 | + `array`
76 | + `function`
77 |
78 | ```javascript
79 | const foo = [1, 2];
80 | const bar = foo;
81 |
82 | bar[0] = 9;
83 |
84 | console.log(foo[0], bar[0]); // => 9, 9
85 | ```
86 |
87 | **[⬆ back to top](#목차)**
88 |
89 | ## 참조(References)
90 |
91 | - [2.1](#2.1) Use `const` for all of your references; avoid using `var`.
92 | - [2.1](#2.1) 모든 참조는 `const` 를 사용하고, `var` 를 사용하지 마십시오.
93 |
94 | > Why? This ensures that you can't reassign your references, which can lead to bugs and difficult to comprehend code.
95 |
96 | > 왜? 참조를 재할당 할 수 없으므로, 버그로 이어지고 이해하기 어려운 코드가 되는것을 방지합니다.
97 |
98 | ```javascript
99 | // bad
100 | var a = 1;
101 | var b = 2;
102 |
103 | // good
104 | const a = 1;
105 | const b = 2;
106 | ```
107 |
108 | - [2.2](#2.2) If you must reassign references, use `let` instead of `var`.
109 | - [2.2](#2.2) 참조를 재할당 해야한다면 `var` 대신 `let` 을 사용하십시오.
110 |
111 | > Why? `let` is block-scoped rather than function-scoped like `var`.
112 |
113 | > 왜? `var` 같은 함수스코프 보다는 오히려 블록스코프의 `let`
114 |
115 | ```javascript
116 | // bad
117 | var count = 1;
118 | if (true) {
119 | count += 1;
120 | }
121 |
122 | // good, use the let.
123 | let count = 1;
124 | if (true) {
125 | count += 1;
126 | }
127 | ```
128 |
129 | - [2.3](#2.3) Note that both `let` and `const` are block-scoped.
130 | - [2.3](#2.3) `let` 과 `const` 는 같이 블록스코프라는것을 유의하십시오.
131 |
132 | ```javascript
133 | // const and let only exist in the blocks they are defined in.
134 | // const 와 let 은 선언된 블록의 안에서만 존재합니다.
135 | {
136 | let a = 1;
137 | const b = 1;
138 | }
139 | console.log(a); // ReferenceError
140 | console.log(b); // ReferenceError
141 | ```
142 |
143 | **[⬆ back to top](#목차)**
144 |
145 | ## 오브젝트(Objects)
146 |
147 | - [3.1](#3.1) Use the literal syntax for object creation.
148 | - [3.1](#3.1) 오브젝트를 작성할때는, 리터럴 구문을 사용하십시오.
149 |
150 | ```javascript
151 | // bad
152 | const item = new Object();
153 |
154 | // good
155 | const item = {};
156 | ```
157 |
158 | - [3.2](#3.2) If your code will be executed in browsers in script context, don't use [reserved words](http://es5.github.io/#x7.6.1) as keys. It won't work in IE8. [More info](https://github.com/airbnb/javascript/issues/61). It’s OK to use them in ES6 modules and server-side code.
159 | - [3.2](#3.2) 코드가 브라우저상의 스크립트로 실행될때 [예약어](http://es5.github.io/#x7.6.1)를 키로 이용하지 마십시오. IE8에서 작동하지 않습니다. [More info](https://github.com/airbnb/javascript/issues/61) 하지만 ES6 모듈안이나 서버사이드에서는 이용가능합니다.
160 |
161 | ```javascript
162 | // bad
163 | const superman = {
164 | default: { clark: 'kent' },
165 | private: true,
166 | };
167 |
168 | // good
169 | const superman = {
170 | defaults: { clark: 'kent' },
171 | hidden: true,
172 | };
173 | ```
174 |
175 | - [3.3](#3.3) Use readable synonyms in place of reserved words.
176 | - [3.3](#3.3) 예약어 대신 알기쉬운 동의어를 사용해 주십시오.
177 |
178 | ```javascript
179 | // bad
180 | const superman = {
181 | class: 'alien',
182 | };
183 |
184 | // bad
185 | const superman = {
186 | klass: 'alien',
187 | };
188 |
189 | // good
190 | const superman = {
191 | type: 'alien',
192 | };
193 | ```
194 |
195 |
196 | - [3.4](#3.4) Use computed property names when creating objects with dynamic property names.
197 | - [3.4](#3.4) 동적 프로퍼티명을 갖는 오브젝트를 작성할때, 계산된 프로퍼티명(computed property names)을 이용해 주십시오.
198 |
199 | > Why? They allow you to define all the properties of an object in one place.
200 |
201 | > 왜? 오브젝트의 모든 프로퍼티를 한 장소에서 정의 할 수 있습니다.
202 |
203 | ```javascript
204 | function getKey(k) {
205 | return a `key named ${k}`;
206 | }
207 |
208 | // bad
209 | const obj = {
210 | id: 5,
211 | name: 'San Francisco',
212 | };
213 | obj[getKey('enabled')] = true;
214 |
215 | // good
216 | const obj = {
217 | id: 5,
218 | name: 'San Francisco',
219 | [getKey('enabled')]: true
220 | };
221 | ```
222 |
223 |
224 | - [3.5](#3.5) Use object method shorthand.
225 | - [3.5](#3.5) 메소드의 단축구문을 이용해 주십시오.
226 |
227 | ```javascript
228 | // bad
229 | const atom = {
230 | value: 1,
231 |
232 | addValue: function (value) {
233 | return atom.value + value;
234 | },
235 | };
236 |
237 | // good
238 | const atom = {
239 | value: 1,
240 |
241 | addValue(value) {
242 | return atom.value + value;
243 | },
244 | };
245 | ```
246 |
247 |
248 | - [3.6](#3.6) Use property value shorthand.
249 | - [3.6](#3.6) 프로퍼티의 단축구문을 이용해 주십시오.
250 |
251 | > Why? It is shorter to write and descriptive.
252 |
253 | > 왜? 기술과 설명이 간결해지기 때문입니다.
254 |
255 | ```javascript
256 | const lukeSkywalker = 'Luke Skywalker';
257 |
258 | // bad
259 | const obj = {
260 | lukeSkywalker: lukeSkywalker,
261 | };
262 |
263 | // good
264 | const obj = {
265 | lukeSkywalker,
266 | };
267 | ```
268 |
269 | - [3.7](#3.7) Group your shorthand properties at the beginning of your object declaration.
270 | - [3.7](#3.7) 프로퍼티의 단축구문은 오브젝트 선언의 시작부분에 그룹화 해주십시오.
271 |
272 | > Why? It's easier to tell which properties are using the shorthand.
273 |
274 | > 왜? 어떤 프로퍼티가 단축구문을 이용하고 있는지가 알기쉽기 때문입니다.
275 |
276 | ```javascript
277 | const anakinSkywalker = 'Anakin Skywalker';
278 | const lukeSkywalker = 'Luke Skywalker';
279 |
280 | // bad
281 | const obj = {
282 | episodeOne: 1,
283 | twoJediWalkIntoACantina: 2,
284 | lukeSkywalker,
285 | episodeThree: 3,
286 | mayTheFourth: 4,
287 | anakinSkywalker,
288 | };
289 |
290 | // good
291 | const obj = {
292 | lukeSkywalker,
293 | anakinSkywalker,
294 | episodeOne: 1,
295 | twoJediWalkIntoACantina: 2,
296 | episodeThree: 3,
297 | mayTheFourth: 4,
298 | };
299 | ```
300 |
301 | **[⬆ back to top](#목차)**
302 |
303 | ## 배열(Arrays)
304 |
305 | - [4.1](#4.1) Use the literal syntax for array creation.
306 | - [4.1](#4.1) 배열을 작성 할 때는 리터럴 구문을 사용해 주십시오.
307 |
308 | ```javascript
309 | // bad
310 | const items = new Array();
311 |
312 | // good
313 | const items = [];
314 | ```
315 |
316 | - [4.2](#4.2) Use Array#push instead of direct assignment to add items to an array.
317 | - [4.2](#4.2) 직접 배열에 항목을 대입하지 말고, Array#push를 이용해 주십시오.
318 |
319 | ```javascript
320 | const someStack = [];
321 |
322 | // bad
323 | someStack[someStack.length] = 'abracadabra';
324 |
325 | // good
326 | someStack.push('abracadabra');
327 | ```
328 |
329 |
330 | - [4.3](#4.3) Use array spreads `...` to copy arrays.
331 |
332 | - [4.3](#4.3) 배열을 복사할때는 배열의 확장연산자 `...` 를 이용해 주십시오.
333 |
334 | ```javascript
335 | // bad
336 | const len = items.length;
337 | const itemsCopy = [];
338 | let i;
339 |
340 | for (i = 0; i < len; i++) {
341 | itemsCopy[i] = items[i];
342 | }
343 |
344 | // good
345 | const itemsCopy = [...items];
346 | ```
347 |
348 | - [4.4](#4.4) To convert an array-like object to an array, use Array#from.
349 | - [4.4](#4.4) array-like 오브젝트를 배열로 변환하는 경우는 Array#from을 이용해 주십시오.
350 |
351 | ```javascript
352 | const foo = document.querySelectorAll('.foo');
353 | const nodes = Array.from(foo);
354 | ```
355 |
356 | **[⬆ back to top](#목차)**
357 |
358 | ## 구조화대입(Destructuring)
359 |
360 | - [5.1](#5.1) Use object destructuring when accessing and using multiple properties of an object.
361 | - [5.1](#5.1) 하나의 오브젝트에서 복수의 프로퍼티를 억세스 할 때는 오브젝트 구조화대입을 이용해 주십시오.
362 |
363 | > Why? Destructuring saves you from creating temporary references for those properties.
364 |
365 | > 왜? 구조화대입을 이용하는 것으로 프로퍼티를 위한 임시적인 참조의 작성을 줄일 수 있습니다.
366 |
367 | ```javascript
368 | // bad
369 | function getFullName(user) {
370 | const firstName = user.firstName;
371 | const lastName = user.lastName;
372 |
373 | return `${firstName} ${lastName}`;
374 | }
375 |
376 | // good
377 | function getFullName(obj) {
378 | const { firstName, lastName } = obj;
379 | return `${firstName} ${lastName}`;
380 | }
381 |
382 | // best
383 | function getFullName({ firstName, lastName }) {
384 | return `${firstName} ${lastName}`;
385 | }
386 | ```
387 |
388 | - [5.2](#5.2) Use array destructuring.
389 | - [5.2](#5.2) 배열의 구조화대입을 이용해 주십시오.
390 |
391 | ```javascript
392 | const arr = [1, 2, 3, 4];
393 |
394 | // bad
395 | const first = arr[0];
396 | const second = arr[1];
397 |
398 | // good
399 | const [first, second] = arr;
400 | ```
401 |
402 | - [5.3](#5.3) Use object destructuring for multiple return values, not array destructuring.
403 | - [5.3](#5.3) 복수의 값을 반환하는 경우는 배열의 구조화대입이 아닌 오브젝트의 구조화대입을 이용해 주십시오.
404 |
405 | > Why? You can add new properties over time or change the order of things without breaking call sites.
406 |
407 | > 왜? 이렇게 함으로써 나중에 호출처에 영향을 주지않고 새로운 프로퍼티를 추가하거나 순서를 변경할수 있습니다.
408 |
409 | ```javascript
410 | // bad
411 | function processInput(input) {
412 | // then a miracle occurs
413 | // 그리고 기적이 일어납니다.
414 | return [left, right, top, bottom];
415 | }
416 |
417 | // the caller needs to think about the order of return data
418 | // 호출처에서 반환된 데이터의 순서를 고려할 필요가 있습니다.
419 | const [left, __, top] = processInput(input);
420 |
421 | // good
422 | function processInput(input) {
423 | // then a miracle occurs
424 | // 그리고 기적이 일어납니다.
425 | return { left, right, top, bottom };
426 | }
427 |
428 | // the caller selects only the data they need
429 | // 호출처에서는 필요한 데이터만 선택하면 됩니다.
430 | const { left, right } = processInput(input);
431 | ```
432 |
433 |
434 | **[⬆ back to top](#목차)**
435 |
436 | ## 문자열(Strings)
437 |
438 | - [6.1](#6.1) Use single quotes `''` for strings.
439 | - [6.1](#6.1) 문자열에는 싱크쿼트 `''` 를 사용해 주십시오.
440 |
441 | ```javascript
442 | // bad
443 | const name = "Capt. Janeway";
444 |
445 | // good
446 | const name = 'Capt. Janeway';
447 | ```
448 |
449 | - [6.2](#6.2) Strings longer than 100 characters should be written across multiple lines using string concatenation.
450 | - [6.2](#6.2) 100문자 이상의 문자열은 문자열연결을 사용해서 복수행에 걸쳐 기술할 필요가 있습니다.
451 |
452 | - [6.3](#6.3) Note: If overused, long strings with concatenation could impact performance. [jsPerf](http://jsperf.com/ya-string-concat) & [Discussion](https://github.com/airbnb/javascript/issues/40).
453 | - [6.3](#6.3) 주의: 문자연결을 과용하면 성능에 영향을 미칠 수 있습니다. [jsPerf](http://jsperf.com/ya-string-concat) & [Discussion](https://github.com/airbnb/javascript/issues/40).
454 |
455 | ```javascript
456 | // bad
457 | const 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.';
458 |
459 | // bad
460 | const errorMessage = 'This is a super long error that was thrown because \
461 | of Batman. When you stop to think about how Batman had anything to do \
462 | with this, you would get nowhere \
463 | fast.';
464 |
465 | // good
466 | const errorMessage = 'This is a super long error that was thrown because ' +
467 | 'of Batman. When you stop to think about how Batman had anything to do ' +
468 | 'with this, you would get nowhere fast.';
469 | ```
470 |
471 |
472 | - [6.4](#6.4) When programmatically building up strings, use template strings instead of concatenation.
473 | - [6.4](#6.4) 프로그램에서 문자열을 생성하는 경우는 문자열 연결이 아닌 template strings를 이용해 주십시오.
474 |
475 | > Why? Template strings give you a readable, concise syntax with proper newlines and string interpolation features.
476 |
477 | > 왜? Template strings 는 문자열 보간기능과 적절한 줄바꿈 기능을 갖는 간결한 구문으로 가독성이 좋기 때문입니다.
478 |
479 | ```javascript
480 | // bad
481 | function sayHi(name) {
482 | return 'How are you, ' + name + '?';
483 | }
484 |
485 | // bad
486 | function sayHi(name) {
487 | return ['How are you, ', name, '?'].join();
488 | }
489 |
490 | // good
491 | function sayHi(name) {
492 | return `How are you, ${name}?`;
493 | }
494 | ```
495 | - [6.5](#6.5) Never use `eval()` on a string, it opens too many vulnerabilities.
496 | - [6.5](#6.5) 절대로 `eval()` 을 이용하지 마십시오. 이것은 많은 취약점을 만들기 때문입니다.
497 |
498 | **[⬆ back to top](#목차)**
499 |
500 |
501 | ## 함수(Functions)
502 |
503 | - [7.1](#7.1) Use function declarations instead of function expressions.
504 | - [7.1](#7.1) 함수식 보다 함수선언을 이용해 주십시오.
505 |
506 | > Why? Function declarations are named, so they're easier to identify in call stacks. Also, the whole body of a function declaration is hoisted, whereas only the reference of a function expression is hoisted. This rule makes it possible to always use [Arrow Functions](#arrow-함수arrow-functions) in place of function expressions.
507 |
508 | > 왜? 이름이 부여된 함수선언은 콜스택에서 간단하게 확인하는 것이 가능합니다. 또한 함수선언은 함수의 본체가 hoist 되어집니다. 그에 반해 함수식은 참조만이 hoist 되어집니다.
509 | 이 룰에 의해 함수식의 부분을 항상 [Arrow함수](#arrow함수arrow-functions)에서 이용하는것이 가능합니다.
510 |
511 | ```javascript
512 | // bad
513 | const foo = function () {
514 | };
515 |
516 | // good
517 | function foo() {
518 | }
519 | ```
520 |
521 | - [7.2](#7.2) Function expressions:
522 | - [7.2](#7.2) 함수식
523 |
524 | ```javascript
525 | // immediately-invoked function expression (IIFE)
526 | // 즉시 실행 함수식(IIFE)
527 | (() => {
528 | console.log('Welcome to the Internet. Please follow me.');
529 | })();
530 | ```
531 |
532 | - [7.3](#7.3) Never declare a function in a non-function block (if, while, etc). Assign the function to a variable instead. Browsers will allow you to do it, but they all interpret it differently, which is bad news bears.
533 | - [7.3](#7.3) 함수이외의 블록 (if나 while같은) 안에서 함수를 선언하지 마십시오. 변수에 함수를 대입하는 대신 브라우저들은 그것을 허용하지만 모두가 다르게 해석합니다.
534 |
535 | - [7.4](#7.4) **Note:** ECMA-262 defines a `block` as a list of statements. A function declaration is not a statement. [Read ECMA-262's note on this issue](http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf#page=97).
536 | - [7.4](#7.4) **주의:** ECMA-262 사양에서는 `block` 은 statements의 일람으로 정의되어 있지만 함수선언은 statements 가 아닙니다. [Read ECMA-262's note on this issue](http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf#page=97).
537 |
538 | ```javascript
539 | // bad
540 | if (currentUser) {
541 | function test() {
542 | console.log('Nope.');
543 | }
544 | }
545 |
546 | // good
547 | let test;
548 | if (currentUser) {
549 | test = () => {
550 | console.log('Yup.');
551 | };
552 | }
553 | ```
554 |
555 | - [7.5](#7.5) Never name a parameter `arguments`. This will take precedence over the `arguments` object that is given to every function scope.
556 | - [7.5](#7.5) 절대 파라메터에 `arguments` 를 지정하지 마십시오. 이것은 함수스코프에 전해지는 `arguments` 오브젝트의 참조를 덮어써 버립니다.
557 |
558 | ```javascript
559 | // bad
560 | function nope(name, options, arguments) {
561 | // ...stuff...
562 | }
563 |
564 | // good
565 | function yup(name, options, args) {
566 | // ...stuff...
567 | }
568 | ```
569 |
570 |
571 | - [7.6](#7.6) Never use `arguments`, opt to use rest syntax `...` instead.
572 | - [7.6](#7.6) 절대 `arguments` 를 이용하지 마십시오. 대신에 rest syntax `...` 를 이용해 주십시오.
573 |
574 | > Why? `...` is explicit about which arguments you want pulled. Plus rest arguments are a real Array and not Array-like like `arguments`.
575 |
576 | > 왜? `...` 을 이용하는것으로 몇개의 파라메터를 이용하고 싶은가를 확실하게 할 수 있습니다. 더해서 rest 파라메터는 `arguments` 와 같은 Array-like 오브젝트가 아닌 진짜 Array 입니다.
577 |
578 | ```javascript
579 | // bad
580 | function concatenateAll() {
581 | const args = Array.prototype.slice.call(arguments);
582 | return args.join('');
583 | }
584 |
585 | // good
586 | function concatenateAll(...args) {
587 | return args.join('');
588 | }
589 | ```
590 |
591 |
592 | - [7.7](#7.7) Use default parameter syntax rather than mutating function arguments.
593 | - [7.7](#7.7) 함수의 파라메터를 변이시키는 것보다 default 파라메터를 이용해 주십시오.
594 |
595 | ```javascript
596 | // really bad
597 | function handleThings(opts) {
598 | // No! We shouldn't mutate function arguments.
599 | // Double bad: if opts is falsy it'll be set to an object which may
600 | // be what you want but it can introduce subtle bugs.
601 |
602 | // 안돼!함수의 파라메터를 변이시키면 안됩니다.
603 | // 만약 opts가 falsy 하다면 바라는데로 오브젝트가 설정됩니다.
604 | // 하지만 미묘한 버그를 일으킬지도 모릅니다.
605 | opts = opts || {};
606 | // ...
607 | }
608 |
609 | // still bad
610 | function handleThings(opts) {
611 | if (opts === void 0) {
612 | opts = {};
613 | }
614 | // ...
615 | }
616 |
617 | // good
618 | function handleThings(opts = {}) {
619 | // ...
620 | }
621 | ```
622 |
623 | - [7.8](#7.8) Avoid side effects with default parameters.
624 | - [7.8](#7.8) side effect가 있을 default 파라메터의 이용은 피해 주십시오.
625 |
626 | > Why? They are confusing to reason about.
627 |
628 | > 왜? 혼란을 야기하기 때문입니다.
629 |
630 | ```javascript
631 | var b = 1;
632 | // bad
633 | function count(a = b++) {
634 | console.log(a);
635 | }
636 | count(); // 1
637 | count(); // 2
638 | count(3); // 3
639 | count(); // 3
640 | ```
641 |
642 | - [7.9](#7.9) Always put default parameters last.
643 | - [7.9](#7.9) 항상 default 파라메터는 뒤쪽에 두십시오.
644 |
645 | ```javascript
646 | // bad
647 | function handleThings(opts = {}, name) {
648 | // ...
649 | }
650 |
651 | // good
652 | function handleThings(name, opts = {}) {
653 | // ...
654 | }
655 | ```
656 |
657 | - [7.10](#7.10) Never use the Function constructor to create a new function.
658 | - [7.10](#7.10) 절대 새 함수를 작성하기 위해 Function constructor를 이용하지 마십시오.
659 |
660 | > Why? Creating a function in this way evaluates a string similarly to eval(), which opens vulnerabilities.
661 |
662 | > 왜? 이 방법으로 문자열을 평가시켜 새 함수를 작성하는것은 eval() 과 같은 수준의 취약점을 일으킬 수 있습니다.
663 |
664 | ```javascript
665 | // bad
666 | var add = new Function('a', 'b', 'return a + b');
667 |
668 | // still bad
669 | var subtract = Function('a', 'b', 'return a - b');
670 | ```
671 |
672 | **[⬆ back to top](#목차)**
673 |
674 | ## Arrow함수(Arrow Functions)
675 |
676 | - [8.1](#8.1) When you must use function expressions (as when passing an anonymous function), use arrow function notation.
677 | - [8.1](#8.1) (무명함수를 전달하는 듯한)함수식을 이용하는 경우 arrow함수 표기를 이용해 주십시오.
678 |
679 | > Why? It creates a version of the function that executes in the context of `this`, which is usually what you want, and is a more concise syntax.
680 |
681 | > 왜? arrow함수는 그 context의 `this` 에서 실행하는 버전의 함수를 작성합니다. 이것은 통상 기대대로의 동작을 하고, 보다 간결한 구문이기 때문입니다.
682 |
683 | > Why not? If you have a fairly complicated function, you might move that logic out into its own function declaration.
684 |
685 | > 이용해야만 하지 않나? 복잡한 함수에서 로직을 정의한 함수의 바깥으로 이동하고 싶을때.
686 |
687 | ```javascript
688 | // bad
689 | [1, 2, 3].map(function (x) {
690 | const y = x + 1;
691 | return x * y;
692 | });
693 |
694 | // good
695 | [1, 2, 3].map((x) => {
696 | const y = x + 1;
697 | return x * y;
698 | });
699 | ```
700 |
701 | - [8.2](#8.2) If the function body consists of a single expression, feel free to omit the braces and use the implicit return. Otherwise use a `return` statement.
702 | - [8.2](#8.2) 함수의 본체가 하나의 식으로 구성된 경우에는 중괄호({})를 생략하고 암시적 return을 이용하는것이 가능합니다. 그 외에는 `return` 문을 이용해 주십시오.
703 |
704 | > Why? Syntactic sugar. It reads well when multiple functions are chained together.
705 |
706 | > 왜? 문법 설탕이니까요. 복수의 함수가 연결된 경우에 읽기 쉬워집니다.
707 |
708 | > Why not? If you plan on returning an object.
709 |
710 | > 사용해야만 하지 않아? 오브젝트를 반환할때.
711 |
712 | ```javascript
713 | // good
714 | [1, 2, 3].map(number => `A string containing the ${number}.`);
715 |
716 | // bad
717 | [1, 2, 3].map(number => {
718 | const nextNumber = number + 1;
719 | `A string containing the ${nextNumber}.`;
720 | });
721 |
722 | // good
723 | [1, 2, 3].map(number => {
724 | const nextNumber = number + 1;
725 | return `A string containing the ${nextNumber}.`;
726 | });
727 | ```
728 |
729 | - [8.3](#8.3) In case the expression spans over multiple lines, wrap it in parentheses for better readability.
730 | - [8.3](#8.3) 식이 복수행에 걸쳐있을 경우는 가독성을 더욱 좋게하기 위해 소괄호()로 감싸 주십시오.
731 |
732 | > Why? It shows clearly where the function starts and ends.
733 |
734 | > 왜? 함수의 개시와 종료부분이 알기쉽게 보이기 때문입니다.
735 |
736 | ```js
737 | // bad
738 | [1, 2, 3].map(number => 'As time went by, the string containing the ' +
739 | `${number} became much longer. So we needed to break it over multiple ` +
740 | 'lines.'
741 | );
742 |
743 | // good
744 | [1, 2, 3].map(number => (
745 | `As time went by, the string containing the ${number} became much ` +
746 | 'longer. So we needed to break it over multiple lines.'
747 | ));
748 | ```
749 |
750 | - [8.4](#8.4) If your function only takes a single argument, feel free to omit the parentheses.
751 | - [8.4](#8.4) 함수의 인수가 하나인 경우 소괄호()를 생략하는게 가능합니다.
752 |
753 | > Why? Less visual clutter.
754 |
755 | > 왜? 별로 보기 어렵지 않기 때문입니다.
756 |
757 | ```javascript
758 | // good
759 | [1, 2, 3].map(x => x * x);
760 |
761 | // good
762 | [1, 2, 3].reduce((y, x) => x + y);
763 | ```
764 |
765 | **[⬆ back to top](#목차)**
766 |
767 |
768 | ## Classes & Constructors
769 |
770 | - [9.1](#9.1) Always use `class`. Avoid manipulating `prototype` directly.
771 | - [9.1](#9.1) `prototype` 을 직접 조작하는것을 피하고 항상 `class` 를 이용해 주십시오.
772 |
773 | > Why? `class` syntax is more concise and easier to reason about.
774 |
775 | > 왜? `class` 구문은 간결하고 의미를 알기 쉽기 때문입니다.
776 |
777 | ```javascript
778 | // bad
779 | function Queue(contents = []) {
780 | this._queue = [...contents];
781 | }
782 | Queue.prototype.pop = function() {
783 | const value = this._queue[0];
784 | this._queue.splice(0, 1);
785 | return value;
786 | }
787 |
788 | // good
789 | class Queue {
790 | constructor(contents = []) {
791 | this._queue = [...contents];
792 | }
793 | pop() {
794 | const value = this._queue[0];
795 | this._queue.splice(0, 1);
796 | return value;
797 | }
798 | }
799 | ```
800 |
801 | - [9.2](#9.2) Use `extends` for inheritance.
802 | - [9.2](#9.2) 상속은 `extends` 를 이용해 주십시오.
803 |
804 | > Why? It is a built-in way to inherit prototype functionality without breaking `instanceof`.
805 |
806 | > 왜? `instanceof` 를 파괴하지 않고 프로토타입 상속을 하기 위해 빌트인 된 방법이기 때문입니다.
807 |
808 | ```javascript
809 | // bad
810 | const inherits = require('inherits');
811 | function PeekableQueue(contents) {
812 | Queue.apply(this, contents);
813 | }
814 | inherits(PeekableQueue, Queue);
815 | PeekableQueue.prototype.peek = function() {
816 | return this._queue[0];
817 | }
818 |
819 | // good
820 | class PeekableQueue extends Queue {
821 | peek() {
822 | return this._queue[0];
823 | }
824 | }
825 | ```
826 |
827 | - [9.3](#9.3) Methods can return `this` to help with method chaining.
828 | - [9.3](#9.3) 메소드의 반환값으로 `this` 를 반환하는 것으로 메소드채이닝을 할 수 있습니다.
829 |
830 | ```javascript
831 | // bad
832 | Jedi.prototype.jump = function() {
833 | this.jumping = true;
834 | return true;
835 | };
836 |
837 | Jedi.prototype.setHeight = function(height) {
838 | this.height = height;
839 | };
840 |
841 | const luke = new Jedi();
842 | luke.jump(); // => true
843 | luke.setHeight(20); // => undefined
844 |
845 | // good
846 | class Jedi {
847 | jump() {
848 | this.jumping = true;
849 | return this;
850 | }
851 |
852 | setHeight(height) {
853 | this.height = height;
854 | return this;
855 | }
856 | }
857 |
858 | const luke = new Jedi();
859 |
860 | luke.jump()
861 | .setHeight(20);
862 | ```
863 |
864 |
865 | - [9.4](#9.4) It's okay to write a custom toString() method, just make sure it works successfully and causes no side effects.
866 | - [9.4](#9.4) 독자의 toString()을 작성하는것을 허용하지만 올바르게 동작하는지와 side effect 가 없는지만 확인해 주십시오.
867 |
868 | ```javascript
869 | class Jedi {
870 | constructor(options = {}) {
871 | this.name = options.name || 'no name';
872 | }
873 |
874 | getName() {
875 | return this.name;
876 | }
877 |
878 | toString() {
879 | return `Jedi - ${this.getName()}`;
880 | }
881 | }
882 | ```
883 |
884 | **[⬆ back to top](#목차)**
885 |
886 |
887 | ## 모듈(Modules)
888 |
889 | - [10.1](#10.1) Always use modules (`import`/`export`) over a non-standard module system. You can always transpile to your preferred module system.
890 | - [10.1](#10.1) 비표준 모듈시스템이 아닌 항상 (`import`/`export`) 를 이용해 주십시오. 이렇게 함으로써 선호하는 모듈시스템에 언제라도 옮겨가는게 가능해 집니다.
891 |
892 | > Why? Modules are the future, let's start using the future now.
893 |
894 | > 왜? 모듈은 미래가 있습니다. 지금 그 미래를 사용하여 시작합시다.
895 |
896 | ```javascript
897 | // bad
898 | const AirbnbStyleGuide = require('./AirbnbStyleGuide');
899 | module.exports = AirbnbStyleGuide.es6;
900 |
901 | // ok
902 | import AirbnbStyleGuide from './AirbnbStyleGuide';
903 | export default AirbnbStyleGuide.es6;
904 |
905 | // best
906 | import { es6 } from './AirbnbStyleGuide';
907 | export default es6;
908 | ```
909 |
910 | - [10.2](#10.2) Do not use wildcard imports.
911 | - [10.2](#10.2) wildcard import 는 이용하지 마십시오.
912 |
913 | > Why? This makes sure you have a single default export.
914 |
915 | > 왜? single default export 임을 주의할 필요가 있습니다.
916 |
917 | ```javascript
918 | // bad
919 | import * as AirbnbStyleGuide from './AirbnbStyleGuide';
920 |
921 | // good
922 | import AirbnbStyleGuide from './AirbnbStyleGuide';
923 | ```
924 |
925 | - [10.3](#10.3) And do not export directly from an import.
926 | - [10.3](#10.3) import 문으로부터 직접 export 하는것은 하지말아 주십시오.
927 |
928 | > Why? Although the one-liner is concise, having one clear way to import and one clear way to export makes things consistent.
929 |
930 | > 왜? 한줄짜리는 간결하지만 import 와 export 방법을 명확히 한가지로 해서 일관성을 갖는 것이 가능합니다.
931 |
932 | ```javascript
933 | // bad
934 | // filename es6.js
935 | export { es6 as default } from './airbnbStyleGuide';
936 |
937 | // good
938 | // filename es6.js
939 | import { es6 } from './AirbnbStyleGuide';
940 | export default es6;
941 | ```
942 |
943 | **[⬆ back to top](#목차)**
944 |
945 | ## 이터레이터와 제너레이터(Iterators and Generators)
946 |
947 | - [11.1](#11.1) Don't use iterators. Prefer JavaScript's higher-order functions like `map()` and `reduce()` instead of loops like `for-of`.
948 | - [11.1](#11.1) iterators를 이용하지 마십시오. `for-of` 루프 대신에 `map()` 과 `reduce()` 와 같은 JavaScript 고급함수(higher-order functions)를 이용해 주십시오.
949 |
950 | > Why? This enforces our immutable rule. Dealing with pure functions that return values is easier to reason about than side-effects.
951 |
952 | > 왜? 고급함수는 immutable(불변)룰을 적용합니다. side effect에 대해 추측하는거보다 값을 반환하는 순수 함수를 다루는게 간단하기 때문입니다.
953 |
954 | ```javascript
955 | const numbers = [1, 2, 3, 4, 5];
956 |
957 | // bad
958 | let sum = 0;
959 | for (let num of numbers) {
960 | sum += num;
961 | }
962 |
963 | sum === 15;
964 |
965 | // good
966 | let sum = 0;
967 | numbers.forEach((num) => sum += num);
968 | sum === 15;
969 |
970 | // best (use the functional force)
971 | const sum = numbers.reduce((total, num) => total + num, 0);
972 | sum === 15;
973 | ```
974 |
975 | - [11.2](#11.2) Don't use generators for now.
976 | - [11.2](#11.2) 현시점에서는 generators는 이용하지 마십시오.
977 |
978 | > Why? They don't transpile well to ES5.
979 |
980 | > 왜? ES5로 잘 transpile 하지 않기 때문입니다.
981 |
982 | **[⬆ back to top](#목차)**
983 |
984 |
985 | ## 프로퍼티(Properties)
986 |
987 | - [12.1](#12.1) Use dot notation when accessing properties.
988 | - [12.1](#12.1) 프로퍼티에 억세스하는 경우는 점 `.` 을 사용해 주십시오.
989 |
990 | ```javascript
991 | const luke = {
992 | jedi: true,
993 | age: 28,
994 | };
995 |
996 | // bad
997 | const isJedi = luke['jedi'];
998 |
999 | // good
1000 | const isJedi = luke.jedi;
1001 | ```
1002 |
1003 | - [12.2](#12.2) Use subscript notation `[]` when accessing properties with a variable.
1004 | - [12.2](#12.2) 변수를 사용해 프로퍼티에 억세스하는 경우는 대괄호 `[]` 를 사용해 주십시오.
1005 |
1006 | ```javascript
1007 | const luke = {
1008 | jedi: true,
1009 | age: 28,
1010 | };
1011 |
1012 | function getProp(prop) {
1013 | return luke[prop];
1014 | }
1015 |
1016 | const isJedi = getProp('jedi');
1017 | ```
1018 |
1019 | **[⬆ back to top](#목차)**
1020 |
1021 |
1022 | ## 변수(Variables)
1023 |
1024 | - [13.1](#13.1) Always use `const` to declare variables. Not doing so will result in global variables. We want to avoid polluting the global namespace. Captain Planet warned us of that.
1025 | - [13.1](#13.1) 변수를 선언 할 때는 항상 `const` 를 사용해 주십시오. 그렇게 하지 않으면 글로벌 변수로 선언됩니다. 글로벌 namespace 를 오염시키지 않도록 캡틴플래닛도 경고하고 있습니다.
1026 |
1027 | ```javascript
1028 | // bad
1029 | superPower = new SuperPower();
1030 |
1031 | // good
1032 | const superPower = new SuperPower();
1033 | ```
1034 |
1035 | - [13.2](#13.2) Use one `const` declaration per variable.
1036 | - [13.2](#13.2) 하나의 변수선언에 대해 하나의 `const` 를 이용해 주십시오.
1037 |
1038 | > Why? It's easier to add new variable declarations this way, and you never have to worry about swapping out a `;` for a `,` or introducing punctuation-only diffs.
1039 |
1040 | > 왜? 이 방법의 경우, 간단히 새 변수를 추가하는게 가능합니다. 또한 `,` 를 `;` 로 바꿔버리는 것에 대해 걱정할 필요가 없습니다.
1041 |
1042 | ```javascript
1043 | // bad
1044 | const items = getItems(),
1045 | goSportsTeam = true,
1046 | dragonball = 'z';
1047 |
1048 | // bad
1049 | // (compare to above, and try to spot the mistake)
1050 | const items = getItems(),
1051 | goSportsTeam = true;
1052 | dragonball = 'z';
1053 |
1054 | // good
1055 | const items = getItems();
1056 | const goSportsTeam = true;
1057 | const dragonball = 'z';
1058 | ```
1059 |
1060 | - [13.3](#13.3) Group all your `const`s and then group all your `let`s.
1061 | - [13.3](#13.3) 우선 `const` 를 그룹화하고 다음에 `let` 을 그룹화 해주십시오.
1062 |
1063 | > Why? This is helpful when later on you might need to assign a variable depending on one of the previous assigned variables.
1064 |
1065 | > 왜? 이전에 할당한 변수에 대해 나중에 새 변수를 추가하는 경우에 유용하기 때문입니다.
1066 |
1067 | ```javascript
1068 | // bad
1069 | let i, len, dragonball,
1070 | items = getItems(),
1071 | goSportsTeam = true;
1072 |
1073 | // bad
1074 | let i;
1075 | const items = getItems();
1076 | let dragonball;
1077 | const goSportsTeam = true;
1078 | let len;
1079 |
1080 | // good
1081 | const goSportsTeam = true;
1082 | const items = getItems();
1083 | let dragonball;
1084 | let i;
1085 | let length;
1086 | ```
1087 |
1088 | - [13.4](#13.4) Assign variables where you need them, but place them in a reasonable place.
1089 | - [13.4](#13.4) 변수를 할당할때는 필요하고 합리적인 장소에 두시기 바랍니다.
1090 |
1091 | > Why? `let` and `const` are block scoped and not function scoped.
1092 |
1093 | > 왜? `let` 과 `const` 는 블록스코프이기 때문입니다. 함수스코프가 아닙니다.
1094 |
1095 | ```javascript
1096 | // good
1097 | function() {
1098 | test();
1099 | console.log('doing stuff..');
1100 |
1101 | //..other stuff..
1102 |
1103 | const name = getName();
1104 |
1105 | if (name === 'test') {
1106 | return false;
1107 | }
1108 |
1109 | return name;
1110 | }
1111 |
1112 | // bad - unnecessary function call
1113 | // 필요없는 함수 호출
1114 | function(hasName) {
1115 | const name = getName();
1116 |
1117 | if (!hasName) {
1118 | return false;
1119 | }
1120 |
1121 | this.setFirstName(name);
1122 |
1123 | return true;
1124 | }
1125 |
1126 | // good
1127 | function(hasName) {
1128 | if (!hasName) {
1129 | return false;
1130 | }
1131 |
1132 | const name = getName();
1133 | this.setFirstName(name);
1134 |
1135 | return true;
1136 | }
1137 | ```
1138 |
1139 | **[⬆ back to top](#목차)**
1140 |
1141 |
1142 | ## Hoisting
1143 |
1144 | - [14.1](#14.1) `var` declarations get hoisted to the top of their scope, their assignment does not. `const` and `let` declarations are blessed with a new concept called [Temporal Dead Zones (TDZ)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#Temporal_dead_zone_and_errors_with_let). It's important to know why [typeof is no longer safe](http://es-discourse.com/t/why-typeof-is-no-longer-safe/15).
1145 | - [14.1](#14.1) `var` 선언은 할당이 없이 스코프의 선두에 hoist 됩니다. `const` 와 `let` 선언은[Temporal Dead Zones (TDZ)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#Temporal_dead_zone_and_errors_with_let) 라고 불리는 새로운 컨셉의 혜택을 받고 있습니다. 이것은 [왜 typeof 는 더이상 안전하지 않은가](http://es-discourse.com/t/why-typeof-is-no-longer-safe/15)를 알고있는 것이 중요합니다.
1146 |
1147 | ```javascript
1148 | // we know this wouldn't work (assuming there
1149 | // is no notDefined global variable)
1150 | // (notDefined 가 글로벌변수에 존재하지 않는다고 판정한 경우.)
1151 | // 잘 동작하지 않습니다.
1152 | function example() {
1153 | console.log(notDefined); // => throws a ReferenceError
1154 | }
1155 |
1156 | // creating a variable declaration after you
1157 | // reference the variable will work due to
1158 | // variable hoisting. Note: the assignment
1159 | // value of `true` is not hoisted.
1160 | // 그 변수를 참조하는 코드의 뒤에서 그 변수를 선언한 경우
1161 | // 변수가 hoist 된 상태에서 동작합니다..
1162 | // 주의:`true` 라는 값 자체는 hoist 되지 않습니다.
1163 | function example() {
1164 | console.log(declaredButNotAssigned); // => undefined
1165 | var declaredButNotAssigned = true;
1166 | }
1167 |
1168 | // The interpreter is hoisting the variable
1169 | // declaration to the top of the scope,
1170 | // which means our example could be rewritten as:
1171 | // 인터프리터는 변수선언을 스코프의 선두에 hoist 합니다.
1172 | // 위의 예는 다음과 같이 다시 쓸수 있습니다.
1173 | function example() {
1174 | let declaredButNotAssigned;
1175 | console.log(declaredButNotAssigned); // => undefined
1176 | declaredButNotAssigned = true;
1177 | }
1178 |
1179 | // using const and let
1180 | // const 와 let 을 이용한 경우
1181 | function example() {
1182 | console.log(declaredButNotAssigned); // => throws a ReferenceError
1183 | console.log(typeof declaredButNotAssigned); // => throws a ReferenceError
1184 | const declaredButNotAssigned = true;
1185 | }
1186 | ```
1187 |
1188 | - [14.2](#14.2) Anonymous function expressions hoist their variable name, but not the function assignment.
1189 | - [14.2](#14.2) 무명함수의 경우 함수가 할당되기 전의 변수가 hoist 됩니다.
1190 |
1191 | ```javascript
1192 | function example() {
1193 | console.log(anonymous); // => undefined
1194 |
1195 | anonymous(); // => TypeError anonymous is not a function
1196 |
1197 | var anonymous = function() {
1198 | console.log('anonymous function expression');
1199 | };
1200 | }
1201 | ```
1202 |
1203 | - [14.3](#14.3) Named function expressions hoist the variable name, not the function name or the function body.
1204 | - [14.3](#14.3) 명명함수의 경우도 똑같이 변수가 hoist 됩니다. 함수명이나 함수본체는 hoist 되지 않습니다.
1205 |
1206 | ```javascript
1207 | function example() {
1208 | console.log(named); // => undefined
1209 |
1210 | named(); // => TypeError named is not a function
1211 |
1212 | superPower(); // => ReferenceError superPower is not defined
1213 |
1214 | var named = function superPower() {
1215 | console.log('Flying');
1216 | };
1217 | }
1218 |
1219 | // the same is true when the function name
1220 | // is the same as the variable name.
1221 | // 함수명과 변수명이 같은 경우도 같은 현상이 발생합니다.
1222 | function example() {
1223 | console.log(named); // => undefined
1224 |
1225 | named(); // => TypeError named is not a function
1226 |
1227 | var named = function named() {
1228 | console.log('named');
1229 | }
1230 | }
1231 | ```
1232 |
1233 | - [14.4](#14.4) Function declarations hoist their name and the function body.
1234 | - [14.4](#14.4) 함수선언은 함수명과 함수본체가 hoist 됩니다.
1235 |
1236 | ```javascript
1237 | function example() {
1238 | superPower(); // => Flying
1239 |
1240 | function superPower() {
1241 | console.log('Flying');
1242 | }
1243 | }
1244 | ```
1245 |
1246 | - For more information refer to [JavaScript Scoping & Hoisting](http://www.adequatelygood.com/2010/2/JavaScript-Scoping-and-Hoisting/) by [Ben Cherry](http://www.adequatelygood.com/).
1247 | - 더 자세한건 이쪽을 참고해 주십시오. [JavaScript Scoping & Hoisting](http://www.adequatelygood.com/2010/2/JavaScript-Scoping-and-Hoisting/) by [Ben Cherry](http://www.adequatelygood.com/).
1248 |
1249 | **[⬆ back to top](#목차)**
1250 |
1251 |
1252 | ## 조건식과 등가식(Comparison Operators & Equality)
1253 |
1254 | - [15.1](#15.1) Use `===` and `!==` over `==` and `!=`.
1255 | - [15.1](#15.1) `==` 이나 `!=` 보다 `===` 와 `!==` 을 사용해 주십시오.
1256 |
1257 | - [15.2](#15.2) Conditional statements such as the `if` statement evaluate their expression using coercion with the `ToBoolean` abstract method and always follow these simple rules:
1258 | + **Objects** evaluate to **true**
1259 | + **Undefined** evaluates to **false**
1260 | + **Null** evaluates to **false**
1261 | + **Booleans** evaluate to **the value of the boolean**
1262 | + **Numbers** evaluate to **false** if **+0, -0, or NaN**, otherwise **true**
1263 | + **Strings** evaluate to **false** if an empty string `''`, otherwise **true**
1264 | - [15.2](#15.2) `if` 문과 같은 조건식은 `ToBoolean` 메소드에 의한 강제형변환으로 평가되어 항상 다음과 같은 심플한 룰을 따릅니다.
1265 | + **오브젝트** 는 **true** 로 평가됩니다.
1266 | + **undefined** 는 **false** 로 평가됩니다.
1267 | + **null** 은 **false** 로 평가됩니다.
1268 | + **부울값** 은 **boolean형의 값** 으로 평가됩니다.
1269 | + **수치** 는 **true** 로 평가됩니다. 하지만 **+0, -0, or NaN** 의 경우는 **false** 입니다.
1270 | + **문자열** 은 **true** 로 평가됩니다. 하지만 빈문자 `''` 의 경우는 **false** 입니다.
1271 |
1272 | ```javascript
1273 | if ([0]) {
1274 | // true
1275 | // An array is an object, objects evaluate to true
1276 | // 배열은 오브젝트이므로 true 로 평가됩니다.
1277 | }
1278 | ```
1279 |
1280 | - [15.3](#15.3) Use shortcuts.
1281 | - [15.3](#15.3) 단축형을 사용해 주십시오.
1282 |
1283 | ```javascript
1284 | // bad
1285 | if (name !== '') {
1286 | // ...stuff...
1287 | }
1288 |
1289 | // good
1290 | if (name) {
1291 | // ...stuff...
1292 | }
1293 |
1294 | // bad
1295 | if (collection.length > 0) {
1296 | // ...stuff...
1297 | }
1298 |
1299 | // good
1300 | if (collection.length) {
1301 | // ...stuff...
1302 | }
1303 | ```
1304 |
1305 | - [15.4](#15.4) For more information see [Truth Equality and JavaScript](http://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/#more-2108) by Angus Croll.
1306 | - [15.4](#15.4) 더 자세한건 이쪽을 참고해 주십시오. [Truth Equality and JavaScript](http://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/#more-2108) by Angus Croll.
1307 |
1308 | **[⬆ back to top](#목차)**
1309 |
1310 |
1311 | ## 블록(Blocks)
1312 |
1313 | - [16.1](#16.1) Use braces with all multi-line blocks.
1314 | - [16.1](#16.1) 복수행의 블록에는 중괄호 ({}) 를 사용해 주십시오.
1315 |
1316 | ```javascript
1317 | // bad
1318 | if (test)
1319 | return false;
1320 |
1321 | // good
1322 | if (test) return false;
1323 |
1324 | // good
1325 | if (test) {
1326 | return false;
1327 | }
1328 |
1329 | // bad
1330 | function() { return false; }
1331 |
1332 | // good
1333 | function() {
1334 | return false;
1335 | }
1336 | ```
1337 |
1338 | - [16.2](#16.2) If you're using multi-line blocks with `if` and `else`, put `else` on the same line as your
1339 | `if` block's closing brace.
1340 | - [16.2](#16.2) 복수행 블록의 `if` 와 `else` 를 이용하는 경우 `else` 는 `if` 블록 끝의 중괄호(})와 같은 행에 위치시켜 주십시오.
1341 |
1342 | ```javascript
1343 | // bad
1344 | if (test) {
1345 | thing1();
1346 | thing2();
1347 | }
1348 | else {
1349 | thing3();
1350 | }
1351 |
1352 | // good
1353 | if (test) {
1354 | thing1();
1355 | thing2();
1356 | } else {
1357 | thing3();
1358 | }
1359 | ```
1360 |
1361 |
1362 | **[⬆ back to top](#목차)**
1363 |
1364 |
1365 | ## 코멘트(Comments)
1366 |
1367 | - [17.1](#17.1) Use `/** ... */` for multi-line comments. Include a description, specify types and values for all parameters and return values.
1368 | - [17.1](#17.1) 복수행의 코멘트는 `/** ... */` 을 사용해 주십시오. 그 안에는 설명과 모든 파라메터, 반환값에 대해 형이나 값을 기술해 주십시오.
1369 |
1370 | ```javascript
1371 | // bad
1372 | // make() returns a new element
1373 | // based on the passed in tag name
1374 | //
1375 | // @param {String} tag
1376 | // @return {Element} element
1377 | function make(tag) {
1378 |
1379 | // ...stuff...
1380 |
1381 | return element;
1382 | }
1383 |
1384 | // good
1385 | /**
1386 | * make() returns a new element
1387 | * based on the passed in tag name
1388 | *
1389 | * @param {String} tag
1390 | * @return {Element} element
1391 | */
1392 | function make(tag) {
1393 |
1394 | // ...stuff...
1395 |
1396 | return element;
1397 | }
1398 | ```
1399 |
1400 | - [17.2](#17.2) Use `//` for single line comments. Place single line comments on a newline above the subject of the comment. Put an empty line before the comment unless it's on the first line of a block.
1401 | - [17.2](#17.2) 단일행 코멘트에는 `//` 을 사용해 주십시오. 코멘트를 추가하고 싶은 코드의 상부에 배치해 주십시오. 또한, 코멘트의 앞에 빈행을 넣어 주십시오.
1402 |
1403 | ```javascript
1404 | // bad
1405 | const active = true; // is current tab
1406 |
1407 | // good
1408 | // is current tab
1409 | const active = true;
1410 |
1411 | // bad
1412 | function getType() {
1413 | console.log('fetching type...');
1414 | // set the default type to 'no type'
1415 | const type = this._type || 'no type';
1416 |
1417 | return type;
1418 | }
1419 |
1420 | // good
1421 | function getType() {
1422 | console.log('fetching type...');
1423 |
1424 | // set the default type to 'no type'
1425 | const type = this._type || 'no type';
1426 |
1427 | return type;
1428 | }
1429 |
1430 | // also good
1431 | function getType() {
1432 | // set the default type to 'no type'
1433 | const type = this._type || 'no type';
1434 |
1435 | return type;
1436 | }
1437 | ```
1438 |
1439 | - [17.3](#17.3) Prefixing your comments with `FIXME` or `TODO` helps other developers quickly understand if you're pointing out a problem that needs to be revisited, or if you're suggesting a solution to the problem that needs to be implemented. These are different than regular comments because they are actionable. The actions are `FIXME -- need to figure this out` or `TODO -- need to implement`.
1440 | - [17.3](#17.3) 문제를 지적하고 재고를 촉구하는 경우나 문제의 해결책을 제안하는 경우 등, 코멘트의 앞에 `FIXME` 나 `TODO` 를 붙이는 것으로 다른 개발자의 빠른 이해를 도울수 있습니다. 이런것들은 어떤 액션을 따른다는 의미로 통상의 코멘트와는 다릅니다. 액션이라는 것은 `FIXME -- 해결이 필요` 또는 `TODO -- 구현이 필요` 를 뜻합니다.
1441 |
1442 | - [17.4](#17.4) Use `// FIXME:` to annotate problems.
1443 | - [17.4](#17.4) 문제에 대한 주석으로써 `// FIXME:` 를 사용해 주십시오.
1444 |
1445 | ```javascript
1446 | class Calculator extends Abacus {
1447 | constructor() {
1448 | super();
1449 |
1450 | // FIXME: shouldn't use a global here
1451 | // FIXME: 글로벌변수를 사용해서는 안됨.
1452 | total = 0;
1453 | }
1454 | }
1455 | ```
1456 |
1457 | - [17.5](#17.5) Use `// TODO:` to annotate solutions to problems.
1458 | - [17.5](#17.5) 문제의 해결책에 대한 주석으로 `// TODO:` 를 사용해 주십시오.
1459 |
1460 | ```javascript
1461 | class Calculator extends Abacus {
1462 | constructor() {
1463 | super();
1464 |
1465 | // TODO: total should be configurable by an options param
1466 | // TODO: total 은 옵션 파라메터로 설정해야함.
1467 | this.total = 0;
1468 | }
1469 | }
1470 | ```
1471 |
1472 | **[⬆ back to top](#목차)**
1473 |
1474 |
1475 | ## 공백(Whitespace)
1476 |
1477 | - [18.1](#18.1) Use soft tabs set to 2 spaces.
1478 | - [18.1](#18.1) 탭에는 스페이스 2개를 설정해 주십시오.
1479 |
1480 | ```javascript
1481 | // bad
1482 | function() {
1483 | ∙∙∙∙const name;
1484 | }
1485 |
1486 | // bad
1487 | function() {
1488 | ∙const name;
1489 | }
1490 |
1491 | // good
1492 | function() {
1493 | ∙∙const name;
1494 | }
1495 | ```
1496 |
1497 | - [18.2](#18.2) Place 1 space before the leading brace.
1498 | - [18.2](#18.2) 주요 중괄호 ({}) 앞에는 스페이스를 1개 넣어 주십시오.
1499 |
1500 | ```javascript
1501 | // bad
1502 | function test(){
1503 | console.log('test');
1504 | }
1505 |
1506 | // good
1507 | function test() {
1508 | console.log('test');
1509 | }
1510 |
1511 | // bad
1512 | dog.set('attr',{
1513 | age: '1 year',
1514 | breed: 'Bernese Mountain Dog',
1515 | });
1516 |
1517 | // good
1518 | dog.set('attr', {
1519 | age: '1 year',
1520 | breed: 'Bernese Mountain Dog',
1521 | });
1522 | ```
1523 |
1524 | - [18.3](#18.3) Place 1 space before the opening parenthesis in control statements (`if`, `while` etc.). Place no space before the argument list in function calls and declarations.
1525 | - [18.3](#18.3) 제어구문 (`if` 문이나 `while` 문 등) 의 소괄호 (()) 앞에는 스페이스를 1개 넣어 주십시오. 함수선언이나 함수호출시 인수리스트의 앞에는 스페이스를 넣지 마십시오.
1526 |
1527 | ```javascript
1528 | // bad
1529 | if(isJedi) {
1530 | fight ();
1531 | }
1532 |
1533 | // good
1534 | if (isJedi) {
1535 | fight();
1536 | }
1537 |
1538 | // bad
1539 | function fight () {
1540 | console.log ('Swooosh!');
1541 | }
1542 |
1543 | // good
1544 | function fight() {
1545 | console.log('Swooosh!');
1546 | }
1547 | ```
1548 |
1549 | - [18.4](#18.4) Set off operators with spaces.
1550 | - [18.4](#18.4) 연산자 사이에는 스페이스를 넣어 주십시오.
1551 |
1552 | ```javascript
1553 | // bad
1554 | const x=y+5;
1555 |
1556 | // good
1557 | const x = y + 5;
1558 | ```
1559 |
1560 | - [18.5](#18.5) End files with a single newline character.
1561 | - [18.5](#18.5) 파일 끝에는 개행문자를 1개 넣어 주십시오.
1562 |
1563 | ```javascript
1564 | // bad
1565 | (function(global) {
1566 | // ...stuff...
1567 | })(this);
1568 | ```
1569 |
1570 | ```javascript
1571 | // bad
1572 | (function(global) {
1573 | // ...stuff...
1574 | })(this);↵
1575 | ↵
1576 | ```
1577 |
1578 | ```javascript
1579 | // good
1580 | (function(global) {
1581 | // ...stuff...
1582 | })(this);↵
1583 | ```
1584 |
1585 | - [18.6](#18.6) Use indentation when making long method chains. Use a leading dot, which
1586 | emphasizes that the line is a method call, not a new statement.
1587 | - [18.6](#18.6) 길게 메소드를 채이닝하는 경우는 인덴트를 이용해 주십시오. 행이 새로운 문이 아닌 메소드 호출인 것을 강조하기 위해서 선두에 점 (.) 을 배치해 주십시오.
1588 |
1589 | ```javascript
1590 | // bad
1591 | $('#items').find('.selected').highlight().end().find('.open').updateCount();
1592 |
1593 | // bad
1594 | $('#items').
1595 | find('.selected').
1596 | highlight().
1597 | end().
1598 | find('.open').
1599 | updateCount();
1600 |
1601 | // good
1602 | $('#items')
1603 | .find('.selected')
1604 | .highlight()
1605 | .end()
1606 | .find('.open')
1607 | .updateCount();
1608 |
1609 | // bad
1610 | const leds = stage.selectAll('.led').data(data).enter().append('svg:svg').class('led', true)
1611 | .attr('width', (radius + margin) * 2).append('svg:g')
1612 | .attr('transform', 'translate(' + (radius + margin) + ',' + (radius + margin) + ')')
1613 | .call(tron.led);
1614 |
1615 | // good
1616 | const leds = stage.selectAll('.led')
1617 | .data(data)
1618 | .enter().append('svg:svg')
1619 | .classed('led', true)
1620 | .attr('width', (radius + margin) * 2)
1621 | .append('svg:g')
1622 | .attr('transform', 'translate(' + (radius + margin) + ',' + (radius + margin) + ')')
1623 | .call(tron.led);
1624 | ```
1625 |
1626 | - [18.7](#18.7) Leave a blank line after blocks and before the next statement.
1627 | - [18.7](#18.7) 문의 앞과 블록의 뒤에는 빈행을 남겨 주십시오.
1628 |
1629 | ```javascript
1630 | // bad
1631 | if (foo) {
1632 | return bar;
1633 | }
1634 | return baz;
1635 |
1636 | // good
1637 | if (foo) {
1638 | return bar;
1639 | }
1640 |
1641 | return baz;
1642 |
1643 | // bad
1644 | const obj = {
1645 | foo() {
1646 | },
1647 | bar() {
1648 | },
1649 | };
1650 | return obj;
1651 |
1652 | // good
1653 | const obj = {
1654 | foo() {
1655 | },
1656 |
1657 | bar() {
1658 | },
1659 | };
1660 |
1661 | return obj;
1662 |
1663 | // bad
1664 | const arr = [
1665 | function foo() {
1666 | },
1667 | function bar() {
1668 | },
1669 | ];
1670 | return arr;
1671 |
1672 | // good
1673 | const arr = [
1674 | function foo() {
1675 | },
1676 |
1677 | function bar() {
1678 | },
1679 | ];
1680 |
1681 | return arr;
1682 | ```
1683 |
1684 | - [18.8](#18.8) Do not pad your blocks with blank lines.
1685 | - [18.8](#18.8) 블록에 빈행을 끼워 넣지 마십시오.
1686 |
1687 | ```javascript
1688 | // bad
1689 | function bar() {
1690 |
1691 | console.log(foo);
1692 |
1693 | }
1694 |
1695 | // also bad
1696 | if (baz) {
1697 |
1698 | console.log(qux);
1699 | } else {
1700 | console.log(foo);
1701 |
1702 | }
1703 |
1704 | // good
1705 | function bar() {
1706 | console.log(foo);
1707 | }
1708 |
1709 | // good
1710 | if (baz) {
1711 | console.log(qux);
1712 | } else {
1713 | console.log(foo);
1714 | }
1715 | ```
1716 |
1717 | - [18.9](#18.9) Do not add spaces inside parentheses.
1718 | - [18.9](#18.9) 소괄호()의 안쪽에 스페이스를 추가하지 마십시오.
1719 |
1720 | ```javascript
1721 | // bad
1722 | function bar( foo ) {
1723 | return foo;
1724 | }
1725 |
1726 | // good
1727 | function bar(foo) {
1728 | return foo;
1729 | }
1730 |
1731 | // bad
1732 | if ( foo ) {
1733 | console.log(foo);
1734 | }
1735 |
1736 | // good
1737 | if (foo) {
1738 | console.log(foo);
1739 | }
1740 | ```
1741 |
1742 | - [18.10](#18.10) Do not add spaces inside brackets.
1743 | - [18.10](#18.10) 대괄호([])의 안쪽에 스페이스를 추가하지 마십시오.
1744 |
1745 | ```javascript
1746 | // bad
1747 | const foo = [ 1, 2, 3 ];
1748 | console.log(foo[ 0 ]);
1749 |
1750 | // good
1751 | const foo = [1, 2, 3];
1752 | console.log(foo[0]);
1753 | ```
1754 |
1755 | - [18.11](#18.11) Add spaces inside curly braces.
1756 | - [18.11](#18.11) 중괄호({})의 안쪽에 스페이스를 추가해 주십시오.
1757 |
1758 | ```javascript
1759 | // bad
1760 | const foo = {clark: 'kent'};
1761 |
1762 | // good
1763 | const foo = { clark: 'kent' };
1764 | ```
1765 |
1766 | **[⬆ back to top](#목차)**
1767 |
1768 | ## 콤마(Commas)
1769 |
1770 | - [19.1](#19.1) Leading commas: **Nope.**
1771 | - [19.1](#19.1) 선두의 콤마 **하지마요**
1772 |
1773 | ```javascript
1774 | // bad
1775 | const story = [
1776 | once
1777 | , upon
1778 | , aTime
1779 | ];
1780 |
1781 | // good
1782 | const story = [
1783 | once,
1784 | upon,
1785 | aTime,
1786 | ];
1787 |
1788 | // bad
1789 | const hero = {
1790 | firstName: 'Ada'
1791 | , lastName: 'Lovelace'
1792 | , birthYear: 1815
1793 | , superPower: 'computers'
1794 | };
1795 |
1796 | // good
1797 | const hero = {
1798 | firstName: 'Ada',
1799 | lastName: 'Lovelace',
1800 | birthYear: 1815,
1801 | superPower: 'computers',
1802 | };
1803 | ```
1804 |
1805 | - [19.2](#19.2) Additional trailing comma: **Yup.**
1806 | - [19.2](#19.2) 끝의 콤마 **좋아요**
1807 |
1808 | > Why? This leads to cleaner git diffs. Also, transpilers like Babel will remove the additional trailing comma in the transpiled code which means you don't have to worry about the [trailing comma problem](es5/README.md#commas) in legacy browsers.
1809 |
1810 | > 왜? 이것은 깨끗한 git의 diffs 로 이어집니다. 또한 Babel과 같은 트랜스파일러는 transpile 하는 사이에 쓸데없는 끝의 콤마를 제거합니다. 이것은 레거시브라우저에서의 [불필요한 콤마 문제](./README.md#commas)를 고민할 필요가 없다는것을 의미합니다.
1811 |
1812 | ```javascript
1813 | // bad - git diff without trailing comma
1814 | const hero = {
1815 | firstName: 'Florence',
1816 | - lastName: 'Nightingale'
1817 | + lastName: 'Nightingale',
1818 | + inventorOf: ['coxcomb graph', 'modern nursing']
1819 | };
1820 |
1821 | // good - git diff with trailing comma
1822 | const hero = {
1823 | firstName: 'Florence',
1824 | lastName: 'Nightingale',
1825 | + inventorOf: ['coxcomb chart', 'modern nursing'],
1826 | };
1827 |
1828 | // bad
1829 | const hero = {
1830 | firstName: 'Dana',
1831 | lastName: 'Scully'
1832 | };
1833 |
1834 | const heroes = [
1835 | 'Batman',
1836 | 'Superman'
1837 | ];
1838 |
1839 | // good
1840 | const hero = {
1841 | firstName: 'Dana',
1842 | lastName: 'Scully',
1843 | };
1844 |
1845 | const heroes = [
1846 | 'Batman',
1847 | 'Superman',
1848 | ];
1849 | ```
1850 |
1851 | **[⬆ back to top](#목차)**
1852 |
1853 |
1854 | ## 세미콜론(Semicolons)
1855 |
1856 | - [20.1](#20.1) **Yup.**
1857 | - [20.1](#20.1) **씁시다**
1858 |
1859 | ```javascript
1860 | // bad
1861 | (function() {
1862 | const name = 'Skywalker'
1863 | return name
1864 | })()
1865 |
1866 | // good
1867 | (() => {
1868 | const name = 'Skywalker';
1869 | return name;
1870 | })();
1871 |
1872 | // good (guards against the function becoming an argument when two files with IIFEs are concatenated)
1873 | // good (즉시함수가 연결된 2개의 파일일때 인수가 되는 부분을 보호합니다.
1874 | ;(() => {
1875 | const name = 'Skywalker';
1876 | return name;
1877 | })();
1878 | ```
1879 |
1880 | [Read more](http://stackoverflow.com/questions/7365172/semicolon-before-self-invoking-function/7365214%237365214).
1881 |
1882 | **[⬆ back to top](#목차)**
1883 |
1884 |
1885 | ## 형변환과 강제(Type Casting & Coercion)
1886 |
1887 | - [21.1](#21.1) Perform type coercion at the beginning of the statement.
1888 | - [21.1](#21.1) 문의 선두에서 형의 강제를 행합니다.
1889 |
1890 | - [21.2](#21.2) Strings:
1891 | - [21.2](#21.2) 문자열의 경우:
1892 |
1893 | ```javascript
1894 | // => this.reviewScore = 9;
1895 |
1896 | // bad
1897 | const totalScore = this.reviewScore + '';
1898 |
1899 | // good
1900 | const totalScore = String(this.reviewScore);
1901 | ```
1902 |
1903 | - [21.3](#21.3) Numbers: Use `Number` for type casting and `parseInt` always with a radix for parsing strings.
1904 | - [21.3](#21.3) 수치의 경우: `Number` 로 형변환하는 경우는 `parseInt` 를 이용하고, 항상 형변환을 위한 기수를 인수로 넘겨 주십시오.
1905 |
1906 | ```javascript
1907 | const inputValue = '4';
1908 |
1909 | // bad
1910 | const val = new Number(inputValue);
1911 |
1912 | // bad
1913 | const val = +inputValue;
1914 |
1915 | // bad
1916 | const val = inputValue >> 0;
1917 |
1918 | // bad
1919 | const val = parseInt(inputValue);
1920 |
1921 | // good
1922 | const val = Number(inputValue);
1923 |
1924 | // good
1925 | const val = parseInt(inputValue, 10);
1926 | ```
1927 |
1928 | - [21.4](#21.4) If for whatever reason you are doing something wild and `parseInt` is your bottleneck and need to use Bitshift for [performance reasons](http://jsperf.com/coercion-vs-casting/3), leave a comment explaining why and what you're doing.
1929 | - [21.4](#21.4) 무언가의 이유로 인해 `parseInt` 가 bottleneck 이 되어, [성능적인 이유](http://jsperf.com/coercion-vs-casting/3)로 Bitshift를 사용할 필요가 있는 경우
1930 | 하려고 했던 것에 대해, 왜(why) 와 무엇(what)의 설명을 코멘트로 해서 남겨 주십시오.
1931 |
1932 | ```javascript
1933 | // good
1934 | /**
1935 | * parseInt was the reason my code was slow.
1936 | * Bitshifting the String to coerce it to a
1937 | * Number made it a lot faster.
1938 | * parseInt 가 원인으로 느렸음.
1939 | * Bitshift를 통한 수치로의 문자열 강제 형변환으로
1940 | * 성능을 개선시킴.
1941 | */
1942 | const val = inputValue >> 0;
1943 | ```
1944 |
1945 | - [21.5](#21.5) **Note:** Be careful when using bitshift operations. Numbers are represented as [64-bit values](http://es5.github.io/#x4.3.19), but Bitshift operations always return a 32-bit integer ([source](http://es5.github.io/#x11.7)). Bitshift can lead to unexpected behavior for integer values larger than 32 bits. [Discussion](https://github.com/airbnb/javascript/issues/109). Largest signed 32-bit Int is 2,147,483,647:
1946 | - [21.5](#21.5) **주의:** bitshift를 사용하는 경우의 주의사항. 수치는 [64비트 값](http://es5.github.io/#x4.3.19)으로 표현되어 있으나 bitshift 연산한 경우는 항상 32비트 integer 로 넘겨집니다.([소스](http://es5.github.io/#x11.7)).
1947 | 32비트 이상의 int 를 bitshift 하는 경우 예상치 못한 현상을 야기할 수 있습니다.([토론](https://github.com/airbnb/javascript/issues/109)) 부호가 포함된 32비트 정수의 최대치는 2,147,483,647 입니다.
1948 |
1949 | ```javascript
1950 | 2147483647 >> 0 //=> 2147483647
1951 | 2147483648 >> 0 //=> -2147483648
1952 | 2147483649 >> 0 //=> -2147483647
1953 | ```
1954 |
1955 | - [21.6](#21.6) Booleans:
1956 | - [21.6](#21.6) 부울값의 경우:
1957 |
1958 | ```javascript
1959 | const age = 0;
1960 |
1961 | // bad
1962 | const hasAge = new Boolean(age);
1963 |
1964 | // good
1965 | const hasAge = Boolean(age);
1966 |
1967 | // good
1968 | const hasAge = !!age;
1969 | ```
1970 |
1971 | **[⬆ back to top](#목차)**
1972 |
1973 |
1974 | ## 명명규칙(Naming Conventions)
1975 |
1976 | - [22.1](#22.1) Avoid single letter names. Be descriptive with your naming.
1977 | - [22.1](#22.1) 1문자의 이름은 피해 주십시오. 이름으로부터 의도가 읽혀질수 있게 해주십시오.
1978 |
1979 | ```javascript
1980 | // bad
1981 | function q() {
1982 | // ...stuff...
1983 | }
1984 |
1985 | // good
1986 | function query() {
1987 | // ..stuff..
1988 | }
1989 | ```
1990 |
1991 | - [22.2](#22.2) Use camelCase when naming objects, functions, and instances.
1992 | - [22.2](#22.2) 오브젝트, 함수 그리고 인스턴스에는 camelCase를 사용해 주십시오.
1993 |
1994 | ```javascript
1995 | // bad
1996 | const OBJEcttsssss = {};
1997 | const this_is_my_object = {};
1998 | function c() {}
1999 |
2000 | // good
2001 | const thisIsMyObject = {};
2002 | function thisIsMyFunction() {}
2003 | ```
2004 |
2005 | - [22.3](#22.3) Use PascalCase when naming constructors or classes.
2006 | - [22.3](#22.3) 클래스나 constructor에는 PascalCase 를 사용해 주십시오.
2007 |
2008 | ```javascript
2009 | // bad
2010 | function user(options) {
2011 | this.name = options.name;
2012 | }
2013 |
2014 | const bad = new user({
2015 | name: 'nope',
2016 | });
2017 |
2018 | // good
2019 | class User {
2020 | constructor(options) {
2021 | this.name = options.name;
2022 | }
2023 | }
2024 |
2025 | const good = new User({
2026 | name: 'yup',
2027 | });
2028 | ```
2029 |
2030 | - [22.4](#22.4) Use a leading underscore `_` when naming private properties.
2031 | - [22.4](#22.4) private 프로퍼티명은 선두에 언더스코어 `_` 를사용해 주십시오.
2032 |
2033 | ```javascript
2034 | // bad
2035 | this.__firstName__ = 'Panda';
2036 | this.firstName_ = 'Panda';
2037 |
2038 | // good
2039 | this._firstName = 'Panda';
2040 | ```
2041 |
2042 | - [22.5](#22.5) Don't save references to `this`. Use arrow functions or Function#bind.
2043 | - [22.5](#22.5) `this` 의 참조를 보존하는것은 피해주십시오. arrow함수나 Function#bind 를 이용해 주십시오.
2044 |
2045 | ```javascript
2046 | // bad
2047 | function foo() {
2048 | const self = this;
2049 | return function() {
2050 | console.log(self);
2051 | };
2052 | }
2053 |
2054 | // bad
2055 | function foo() {
2056 | const that = this;
2057 | return function() {
2058 | console.log(that);
2059 | };
2060 | }
2061 |
2062 | // good
2063 | function foo() {
2064 | return () => {
2065 | console.log(this);
2066 | };
2067 | }
2068 | ```
2069 |
2070 | - [22.6](#22.6) If your file exports a single class, your filename should be exactly the name of the class.
2071 | - [22.6](#22.6) 파일을 1개의 클래스로 export 하는 경우, 파일명은 클래스명과 완전히 일치시키지 않으면 안됩니다.
2072 |
2073 | ```javascript
2074 | // file contents
2075 | class CheckBox {
2076 | // ...
2077 | }
2078 | export default CheckBox;
2079 |
2080 | // in some other file
2081 | // bad
2082 | import CheckBox from './checkBox';
2083 |
2084 | // bad
2085 | import CheckBox from './check_box';
2086 |
2087 | // good
2088 | import CheckBox from './CheckBox';
2089 | ```
2090 |
2091 | - [22.7](#22.7) Use camelCase when you export-default a function. Your filename should be identical to your function's name.
2092 | - [22.7](#22.7) Default export가 함수일 경우, camelCase를 이용해 주십시오. 파일명은 함수명과 동일해야 합니다.
2093 |
2094 | ```javascript
2095 | function makeStyleGuide() {
2096 | }
2097 |
2098 | export default makeStyleGuide;
2099 | ```
2100 |
2101 | - [22.8](#22.8) Use PascalCase when you export a singleton / function library / bare object.
2102 | - [22.8](#22.8) singleton / function library / 빈오브젝트를 export 하는 경우, PascalCase를 이용해 주십시오.
2103 |
2104 | ```javascript
2105 | const AirbnbStyleGuide = {
2106 | es6: {
2107 | }
2108 | };
2109 |
2110 | export default AirbnbStyleGuide;
2111 | ```
2112 |
2113 |
2114 | **[⬆ back to top](#목차)**
2115 |
2116 |
2117 | ## 억세서(Accessors)
2118 |
2119 | - [23.1](#23.1) Accessor functions for properties are not required.
2120 | - [23.1](#23.1) 프로퍼티를 위한 억세서 (Accessor) 함수는 필수는 아닙니다.
2121 |
2122 | - [23.2](#23.2) If you do make accessor functions use getVal() and setVal('hello').
2123 | - [23.2](#23.2) 억세서 함수가 필요한 경우, `getVal()` 이나 `setVal('hello')` 로 해주십시오.
2124 |
2125 | ```javascript
2126 | // bad
2127 | dragon.age();
2128 |
2129 | // good
2130 | dragon.getAge();
2131 |
2132 | // bad
2133 | dragon.age(25);
2134 |
2135 | // good
2136 | dragon.setAge(25);
2137 | ```
2138 |
2139 | - [23.3](#23.3) If the property is a `boolean`, use `isVal()` or `hasVal()`.
2140 | - [23.3](#23.3) 프로퍼티가 `boolean` 인 경우, `isVal()` 이나 `hasVal()` 로 해주십시오.
2141 |
2142 | ```javascript
2143 | // bad
2144 | if (!dragon.age()) {
2145 | return false;
2146 | }
2147 |
2148 | // good
2149 | if (!dragon.hasAge()) {
2150 | return false;
2151 | }
2152 | ```
2153 |
2154 | - [23.4](#23.4) It's okay to create get() and set() functions, but be consistent.
2155 | - [23.4](#23.4) 일관된 경우, `get()` 과 `set()` 으로 함수를 작성해도 좋습니다.
2156 |
2157 | ```javascript
2158 | class Jedi {
2159 | constructor(options = {}) {
2160 | const lightsaber = options.lightsaber || 'blue';
2161 | this.set('lightsaber', lightsaber);
2162 | }
2163 |
2164 | set(key, val) {
2165 | this[key] = val;
2166 | }
2167 |
2168 | get(key) {
2169 | return this[key];
2170 | }
2171 | }
2172 | ```
2173 |
2174 | **[⬆ back to top](#목차)**
2175 |
2176 |
2177 | ## 이벤트(Events)
2178 |
2179 | - [24.1](#24.1) When attaching data payloads to events (whether DOM events or something more proprietary like Backbone events), pass a hash instead of a raw value. This allows a subsequent contributor to add more data to the event payload without finding and updating every handler for the event. For example, instead of:
2180 | - [24.1](#24.1) (DOM이벤트나 Backbone events 와 같은 독자의) 이벤트로 payload의 값을 넘길 경우는 raw값 보다는 해시값을 넘겨 주십시오.
2181 | 이렇게 함으로써, 이후 기여자가 이벤트에 관련한 모든 핸들러를 찾아서 갱신하는 대신 이벤트 payload에 값을 추가하는 것이 가능합니다. 예를들면 아래와 같이
2182 |
2183 | ```javascript
2184 | // bad
2185 | $(this).trigger('listingUpdated', listing.id);
2186 |
2187 | ...
2188 |
2189 | $(this).on('listingUpdated', function(e, listingId) {
2190 | // do something with listingId
2191 | });
2192 | ```
2193 |
2194 | prefer:
2195 | 이쪽이 좋습니다:
2196 |
2197 | ```javascript
2198 | // good
2199 | $(this).trigger('listingUpdated', { listingId: listing.id });
2200 |
2201 | ...
2202 |
2203 | $(this).on('listingUpdated', function(e, data) {
2204 | // do something with data.listingId
2205 | });
2206 | ```
2207 |
2208 | **[⬆ back to top](#목차)**
2209 |
2210 |
2211 | ## jQuery
2212 |
2213 | - [25.1](#25.1) Prefix jQuery object variables with a `$`.
2214 | - [25.1](#25.1) jQuery오브젝트의 변수는 선두에 `$` 를 부여해 주십시오.
2215 |
2216 | ```javascript
2217 | // bad
2218 | const sidebar = $('.sidebar');
2219 |
2220 | // good
2221 | const $sidebar = $('.sidebar');
2222 |
2223 | // good
2224 | const $sidebarBtn = $('.sidebar-btn');
2225 | ```
2226 |
2227 | - [25.2](#25.2) Cache jQuery lookups.
2228 | - [25.2](#25.2) jQuery의 검색결과를 캐시해 주십시오.
2229 |
2230 | ```javascript
2231 | // bad
2232 | function setSidebar() {
2233 | $('.sidebar').hide();
2234 |
2235 | // ...stuff...
2236 |
2237 | $('.sidebar').css({
2238 | 'background-color': 'pink'
2239 | });
2240 | }
2241 |
2242 | // good
2243 | function setSidebar() {
2244 | const $sidebar = $('.sidebar');
2245 | $sidebar.hide();
2246 |
2247 | // ...stuff...
2248 |
2249 | $sidebar.css({
2250 | 'background-color': 'pink'
2251 | });
2252 | }
2253 | ```
2254 |
2255 | - [25.3](#25.3) For DOM queries use Cascading `$('.sidebar ul')` or parent > child `$('.sidebar > ul')`. [jsPerf](http://jsperf.com/jquery-find-vs-context-sel/16)
2256 | - [25.3](#25.3) DOM 검색에는 `$('.sidebar ul')` 이나 `$('.sidebar > ul')` 와 같은 Cascading 을 사용해 주십시오. [jsPerf](http://jsperf.com/jquery-find-vs-context-sel/16)
2257 |
2258 | - [25.4](#25.4) Use `find` with scoped jQuery object queries.
2259 | - [25.4](#25.4) 한정된 jQuery 오브젝트 쿼리에는 `find` 를 사용해 주십시오.
2260 |
2261 | ```javascript
2262 | // bad
2263 | $('ul', '.sidebar').hide();
2264 |
2265 | // bad
2266 | $('.sidebar').find('ul').hide();
2267 |
2268 | // good
2269 | $('.sidebar ul').hide();
2270 |
2271 | // good
2272 | $('.sidebar > ul').hide();
2273 |
2274 | // good
2275 | $sidebar.find('ul').hide();
2276 | ```
2277 |
2278 | **[⬆ back to top](#목차)**
2279 |
2280 |
2281 | ## ECMAScript 5 Compatibility
2282 |
2283 | - [26.1](#26.1) Refer to [Kangax](https://twitter.com/kangax/)'s ES5 [compatibility table](http://kangax.github.io/es5-compat-table/).
2284 |
2285 | **[⬆ back to top](#목차)**
2286 |
2287 | ## ECMAScript 6 Styles
2288 |
2289 | - [27.1](#27.1) This is a collection of links to the various es6 features.
2290 |
2291 | 1. [Arrow Functions](#arrow-functions)
2292 | 1. [Classes](#constructors)
2293 | 1. [Object Shorthand](#es6-object-shorthand)
2294 | 1. [Object Concise](#es6-object-concise)
2295 | 1. [Object Computed Properties](#es6-computed-properties)
2296 | 1. [Template Strings](#es6-template-literals)
2297 | 1. [Destructuring](#destructuring)
2298 | 1. [Default Parameters](#es6-default-parameters)
2299 | 1. [Rest](#es6-rest)
2300 | 1. [Array Spreads](#es6-array-spreads)
2301 | 1. [Let and Const](#references)
2302 | 1. [Iterators and Generators](#iterators-and-generators)
2303 | 1. [Modules](#modules)
2304 |
2305 | **[⬆ back to top](#목차)**
2306 |
2307 | ## Testing
2308 |
2309 | - [28.1](#28.1) **Yup.**
2310 |
2311 | ```javascript
2312 | function () {
2313 | return true;
2314 | }
2315 | ```
2316 |
2317 | - [28.2](#28.2) **No, but seriously**:
2318 | - Whichever testing framework you use, you should be writing tests!
2319 | - Strive to write many small pure functions, and minimize where mutations occur.
2320 | - Be cautious about stubs and mocks - they can make your tests more brittle.
2321 | - We primarily use [`mocha`](https://www.npmjs.com/package/mocha) at Airbnb. [`tape`](https://www.npmjs.com/package/tape) is also used occasionally for small, separate modules.
2322 | - 100% test coverage is a good goal to strive for, even if it's not always practical to reach it.
2323 | - Whenever you fix a bug, _write a regression test_. A bug fixed without a regression test is almost certainly going to break again in the future.
2324 |
2325 | **[⬆ back to top](#목차)**
2326 |
2327 |
2328 | ## Performance
2329 |
2330 | - [On Layout & Web Performance](http://www.kellegous.com/j/2013/01/26/layout-performance/)
2331 | - [String vs Array Concat](http://jsperf.com/string-vs-array-concat/2)
2332 | - [Try/Catch Cost In a Loop](http://jsperf.com/try-catch-in-loop-cost)
2333 | - [Bang Function](http://jsperf.com/bang-function)
2334 | - [jQuery Find vs Context, Selector](http://jsperf.com/jquery-find-vs-context-sel/13)
2335 | - [innerHTML vs textContent for script text](http://jsperf.com/innerhtml-vs-textcontent-for-script-text)
2336 | - [Long String Concatenation](http://jsperf.com/ya-string-concat)
2337 | - Loading...
2338 |
2339 | **[⬆ back to top](#목차)**
2340 |
2341 |
2342 | ## Resources
2343 |
2344 | **Learning ES6**
2345 |
2346 | - [Draft ECMA 2015 (ES6) Spec](https://people.mozilla.org/~jorendorff/es6-draft.html)
2347 | - [ExploringJS](http://exploringjs.com/)
2348 | - [ES6 Compatibility Table](https://kangax.github.io/compat-table/es6/)
2349 | - [Comprehensive Overview of ES6 Features](http://es6-features.org/)
2350 |
2351 | **Read This**
2352 |
2353 | - [Standard ECMA-262](http://www.ecma-international.org/ecma-262/6.0/index.html)
2354 |
2355 | **Tools**
2356 |
2357 | - Code Style Linters
2358 | + [ESlint](http://eslint.org/) - [Airbnb Style .eslintrc](https://github.com/airbnb/javascript/blob/master/linters/.eslintrc)
2359 | + [JSHint](http://jshint.com/) - [Airbnb Style .jshintrc](https://github.com/airbnb/javascript/blob/master/linters/jshintrc)
2360 | + [JSCS](https://github.com/jscs-dev/node-jscs) - [Airbnb Style Preset](https://github.com/jscs-dev/node-jscs/blob/master/presets/airbnb.json)
2361 |
2362 | **Other Style Guides**
2363 |
2364 | - [Google JavaScript Style Guide](http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml)
2365 | - [jQuery Core Style Guidelines](http://contribute.jquery.org/style-guide/js/)
2366 | - [Principles of Writing Consistent, Idiomatic JavaScript](https://github.com/rwaldron/idiomatic.js)
2367 |
2368 | **Other Styles**
2369 |
2370 | - [Naming this in nested functions](https://gist.github.com/cjohansen/4135065) - Christian Johansen
2371 | - [Conditional Callbacks](https://github.com/airbnb/javascript/issues/52) - Ross Allen
2372 | - [Popular JavaScript Coding Conventions on Github](http://sideeffect.kr/popularconvention/#javascript) - JeongHoon Byun
2373 | - [Multiple var statements in JavaScript, not superfluous](http://benalman.com/news/2012/05/multiple-var-statements-javascript/) - Ben Alman
2374 |
2375 | **Further Reading**
2376 |
2377 | - [Understanding JavaScript Closures](http://javascriptweblog.wordpress.com/2010/10/25/understanding-javascript-closures/) - Angus Croll
2378 | - [Basic JavaScript for the impatient programmer](http://www.2ality.com/2013/06/basic-javascript.html) - Dr. Axel Rauschmayer
2379 | - [You Might Not Need jQuery](http://youmightnotneedjquery.com/) - Zack Bloom & Adam Schwartz
2380 | - [ES6 Features](https://github.com/lukehoban/es6features) - Luke Hoban
2381 | - [Frontend Guidelines](https://github.com/bendc/frontend-guidelines) - Benjamin De Cock
2382 |
2383 | **Books**
2384 |
2385 | - [JavaScript: The Good Parts](http://www.amazon.com/JavaScript-Good-Parts-Douglas-Crockford/dp/0596517742) - Douglas Crockford
2386 | - [JavaScript Patterns](http://www.amazon.com/JavaScript-Patterns-Stoyan-Stefanov/dp/0596806752) - Stoyan Stefanov
2387 | - [Pro JavaScript Design Patterns](http://www.amazon.com/JavaScript-Design-Patterns-Recipes-Problem-Solution/dp/159059908X) - Ross Harmes and Dustin Diaz
2388 | - [High Performance Web Sites: Essential Knowledge for Front-End Engineers](http://www.amazon.com/High-Performance-Web-Sites-Essential/dp/0596529309) - Steve Souders
2389 | - [Maintainable JavaScript](http://www.amazon.com/Maintainable-JavaScript-Nicholas-C-Zakas/dp/1449327680) - Nicholas C. Zakas
2390 | - [JavaScript Web Applications](http://www.amazon.com/JavaScript-Web-Applications-Alex-MacCaw/dp/144930351X) - Alex MacCaw
2391 | - [Pro JavaScript Techniques](http://www.amazon.com/Pro-JavaScript-Techniques-John-Resig/dp/1590597273) - John Resig
2392 | - [Smashing Node.js: JavaScript Everywhere](http://www.amazon.com/Smashing-Node-js-JavaScript-Everywhere-Magazine/dp/1119962595) - Guillermo Rauch
2393 | - [Secrets of the JavaScript Ninja](http://www.amazon.com/Secrets-JavaScript-Ninja-John-Resig/dp/193398869X) - John Resig and Bear Bibeault
2394 | - [Human JavaScript](http://humanjavascript.com/) - Henrik Joreteg
2395 | - [Superhero.js](http://superherojs.com/) - Kim Joar Bekkelund, Mads Mobæk, & Olav Bjorkoy
2396 | - [JSBooks](http://jsbooks.revolunet.com/) - Julien Bouquillon
2397 | - [Third Party JavaScript](https://www.manning.com/books/third-party-javascript) - Ben Vinegar and Anton Kovalyov
2398 | - [Effective JavaScript: 68 Specific Ways to Harness the Power of JavaScript](http://amzn.com/0321812182) - David Herman
2399 | - [Eloquent JavaScript](http://eloquentjavascript.net/) - Marijn Haverbeke
2400 | - [You Don't Know JS: ES6 & Beyond](http://shop.oreilly.com/product/0636920033769.do) - Kyle Simpson
2401 |
2402 | **Blogs**
2403 |
2404 | - [DailyJS](http://dailyjs.com/)
2405 | - [JavaScript Weekly](http://javascriptweekly.com/)
2406 | - [JavaScript, JavaScript...](http://javascriptweblog.wordpress.com/)
2407 | - [Bocoup Weblog](https://bocoup.com/weblog)
2408 | - [Adequately Good](http://www.adequatelygood.com/)
2409 | - [NCZOnline](https://www.nczonline.net/)
2410 | - [Perfection Kills](http://perfectionkills.com/)
2411 | - [Ben Alman](http://benalman.com/)
2412 | - [Dmitry Baranovskiy](http://dmitry.baranovskiy.com/)
2413 | - [Dustin Diaz](http://dustindiaz.com/)
2414 | - [nettuts](http://code.tutsplus.com/?s=javascript)
2415 |
2416 | **Podcasts**
2417 |
2418 | - [JavaScript Jabber](https://devchat.tv/js-jabber/)
2419 |
2420 |
2421 | **[⬆ back to top](#목차)**
2422 |
2423 | ## In the Wild
2424 |
2425 | 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.
2426 |
2427 | - **Aan Zee**: [AanZee/javascript](https://github.com/AanZee/javascript)
2428 | - **Adult Swim**: [adult-swim/javascript](https://github.com/adult-swim/javascript)
2429 | - **Airbnb**: [airbnb/javascript](https://github.com/airbnb/javascript)
2430 | - **Apartmint**: [apartmint/javascript](https://github.com/apartmint/javascript)
2431 | - **Avalara**: [avalara/javascript](https://github.com/avalara/javascript)
2432 | - **Billabong**: [billabong/javascript](https://github.com/billabong/javascript)
2433 | - **Blendle**: [blendle/javascript](https://github.com/blendle/javascript)
2434 | - **ComparaOnline**: [comparaonline/javascript](https://github.com/comparaonline/javascript-style-guide)
2435 | - **Compass Learning**: [compasslearning/javascript-style-guide](https://github.com/compasslearning/javascript-style-guide)
2436 | - **DailyMotion**: [dailymotion/javascript](https://github.com/dailymotion/javascript)
2437 | - **Digitpaint** [digitpaint/javascript](https://github.com/digitpaint/javascript)
2438 | - **Ecosia**: [ecosia/javascript](https://github.com/ecosia/javascript)
2439 | - **Evernote**: [evernote/javascript-style-guide](https://github.com/evernote/javascript-style-guide)
2440 | - **ExactTarget**: [ExactTarget/javascript](https://github.com/ExactTarget/javascript)
2441 | - **Expensify** [Expensify/Style-Guide](https://github.com/Expensify/Style-Guide/blob/master/javascript.md)
2442 | - **Flexberry**: [Flexberry/javascript-style-guide](https://github.com/Flexberry/javascript-style-guide)
2443 | - **Gawker Media**: [gawkermedia/javascript](https://github.com/gawkermedia/javascript)
2444 | - **General Electric**: [GeneralElectric/javascript](https://github.com/GeneralElectric/javascript)
2445 | - **GoodData**: [gooddata/gdc-js-style](https://github.com/gooddata/gdc-js-style)
2446 | - **Grooveshark**: [grooveshark/javascript](https://github.com/grooveshark/javascript)
2447 | - **How About We**: [howaboutwe/javascript](https://github.com/howaboutwe/javascript-style-guide)
2448 | - **Huballin**: [huballin/javascript](https://github.com/huballin/javascript)
2449 | - **HubSpot**: [HubSpot/javascript](https://github.com/HubSpot/javascript)
2450 | - **Hyper**: [hyperoslo/javascript-playbook](https://github.com/hyperoslo/javascript-playbook/blob/master/style.md)
2451 | - **InfoJobs**: [InfoJobs/JavaScript-Style-Guide](https://github.com/InfoJobs/JavaScript-Style-Guide)
2452 | - **Intent Media**: [intentmedia/javascript](https://github.com/intentmedia/javascript)
2453 | - **Jam3**: [Jam3/JavaScript-Code-Conventions](https://github.com/Jam3/JavaScript-Code-Conventions)
2454 | - **JSSolutions**: [JSSolutions/javascript](https://github.com/JSSolutions/javascript)
2455 | - **Kinetica Solutions**: [kinetica/javascript](https://github.com/kinetica/JavaScript-style-guide)
2456 | - **Mighty Spring**: [mightyspring/javascript](https://github.com/mightyspring/javascript)
2457 | - **MinnPost**: [MinnPost/javascript](https://github.com/MinnPost/javascript)
2458 | - **MitocGroup**: [MitocGroup/javascript](https://github.com/MitocGroup/javascript)
2459 | - **ModCloth**: [modcloth/javascript](https://github.com/modcloth/javascript)
2460 | - **Money Advice Service**: [moneyadviceservice/javascript](https://github.com/moneyadviceservice/javascript)
2461 | - **Muber**: [muber/javascript](https://github.com/muber/javascript)
2462 | - **National Geographic**: [natgeo/javascript](https://github.com/natgeo/javascript)
2463 | - **National Park Service**: [nationalparkservice/javascript](https://github.com/nationalparkservice/javascript)
2464 | - **Nimbl3**: [nimbl3/javascript](https://github.com/nimbl3/javascript)
2465 | - **Orion Health**: [orionhealth/javascript](https://github.com/orionhealth/javascript)
2466 | - **Peerby**: [Peerby/javascript](https://github.com/Peerby/javascript)
2467 | - **Razorfish**: [razorfish/javascript-style-guide](https://github.com/razorfish/javascript-style-guide)
2468 | - **reddit**: [reddit/styleguide/javascript](https://github.com/reddit/styleguide/tree/master/javascript)
2469 | - **REI**: [reidev/js-style-guide](https://github.com/reidev/js-style-guide)
2470 | - **Ripple**: [ripple/javascript-style-guide](https://github.com/ripple/javascript-style-guide)
2471 | - **SeekingAlpha**: [seekingalpha/javascript-style-guide](https://github.com/seekingalpha/javascript-style-guide)
2472 | - **Shutterfly**: [shutterfly/javascript](https://github.com/shutterfly/javascript)
2473 | - **Springload**: [springload/javascript](https://github.com/springload/javascript)
2474 | - **StudentSphere**: [studentsphere/javascript](https://github.com/studentsphere/guide-javascript)
2475 | - **Target**: [target/javascript](https://github.com/target/javascript)
2476 | - **TheLadders**: [TheLadders/javascript](https://github.com/TheLadders/javascript)
2477 | - **T4R Technology**: [T4R-Technology/javascript](https://github.com/T4R-Technology/javascript)
2478 | - **VoxFeed**: [VoxFeed/javascript-style-guide](https://github.com/VoxFeed/javascript-style-guide)
2479 | - **Weggo**: [Weggo/javascript](https://github.com/Weggo/javascript)
2480 | - **Zillow**: [zillow/javascript](https://github.com/zillow/javascript)
2481 | - **ZocDoc**: [ZocDoc/javascript](https://github.com/ZocDoc/javascript)
2482 |
2483 | **[⬆ back to top](#목차)**
2484 |
2485 | ## Translation
2486 |
2487 | This style guide is also available in other languages:
2488 |
2489 | -  **Brazilian Portuguese**: [armoucar/javascript-style-guide](https://github.com/armoucar/javascript-style-guide)
2490 | -  **Bulgarian**: [borislavvv/javascript](https://github.com/borislavvv/javascript)
2491 | -  **Catalan**: [fpmweb/javascript-style-guide](https://github.com/fpmweb/javascript-style-guide)
2492 | -  **Chinese (Simplified)**: [sivan/javascript-style-guide](https://github.com/sivan/javascript-style-guide)
2493 | -  **Chinese (Traditional)**: [jigsawye/javascript](https://github.com/jigsawye/javascript)
2494 | -  **French**: [nmussy/javascript-style-guide](https://github.com/nmussy/javascript-style-guide)
2495 | -  **German**: [timofurrer/javascript-style-guide](https://github.com/timofurrer/javascript-style-guide)
2496 | -  **Italian**: [sinkswim/javascript-style-guide](https://github.com/sinkswim/javascript-style-guide)
2497 | -  **Japanese**: [mitsuruog/javascript-style-guide](https://github.com/mitsuruog/javascript-style-guide)
2498 | -  **Korean**: [tipjs/javascript-style-guide](https://github.com/tipjs/javascript-style-guide)
2499 | -  **Polish**: [mjurczyk/javascript](https://github.com/mjurczyk/javascript)
2500 | -  **Russian**: [uprock/javascript](https://github.com/uprock/javascript)
2501 | -  **Spanish**: [paolocarrasco/javascript-style-guide](https://github.com/paolocarrasco/javascript-style-guide)
2502 | -  **Thai**: [lvarayut/javascript-style-guide](https://github.com/lvarayut/javascript-style-guide)
2503 |
2504 | ## The JavaScript Style Guide Guide
2505 |
2506 | - [Reference](https://github.com/airbnb/javascript/wiki/The-JavaScript-Style-Guide-Guide)
2507 |
2508 | ## Chat With Us About JavaScript
2509 |
2510 | - Find us on [gitter](https://gitter.im/airbnb/javascript).
2511 |
2512 | ## Contributors
2513 |
2514 | - [View Contributors](https://github.com/airbnb/javascript/graphs/contributors)
2515 |
2516 |
2517 | ## License
2518 |
2519 | (The MIT License)
2520 |
2521 | Copyright (c) 2014 Airbnb
2522 |
2523 | Permission is hereby granted, free of charge, to any person obtaining
2524 | a copy of this software and associated documentation files (the
2525 | 'Software'), to deal in the Software without restriction, including
2526 | without limitation the rights to use, copy, modify, merge, publish,
2527 | distribute, sublicense, and/or sell copies of the Software, and to
2528 | permit persons to whom the Software is furnished to do so, subject to
2529 | the following conditions:
2530 |
2531 | The above copyright notice and this permission notice shall be
2532 | included in all copies or substantial portions of the Software.
2533 |
2534 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
2535 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2536 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
2537 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
2538 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
2539 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
2540 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2541 |
2542 |
2543 | **[⬆ back to top](#목차)**
2544 |
2545 | ## Amendments
2546 |
2547 | 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.
2548 |
2549 | # };
2550 |
--------------------------------------------------------------------------------