본문 바로가기

개발/Javascript

(33)
모듈(Modules) 모듈(Modules)Always use modules (import/export) over a non-standard module system. You can always transpile to your preferred module system.10.1 비표준 모듈시스템이 아닌 항상 (import/export) 를 이용해 주십시오. 이렇게 함으로써 선호하는 모듈시스템에 언제라도 옮겨가는게 가능해 집니다.Why? Modules are the future, let's start using the future now.왜? 모듈은 미래가 있습니다. 지금 그 미래를 사용하여 시작합시다.// bad const AirbnbStyleGuide = require('./AirbnbStyleGuide'); module.e..
Classes & Constructors Classes & Constructors항상 class를 사용하십시오. prototype 을 직접 조작하지마시오prototype 을 직접 조작하는것을 피하고 항상 class 를 이용해 주십시오.Why? class syntax is more concise and easier to reason about.왜? class 구문은 간결하고 의미를 알기 쉽기 때문입니다.// bad function Queue(contents = []) { this._queue = [...contents]; } Queue.prototype.pop = function() { const value = this._queue[0]; this._queue.splice(0, 1); return value; } // good class Queu..
함수(Functions) 함수(Functions)Use function declarations instead of function expressions.함수식 보다 함수선언을 이용해 주십시오.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 in place of function expressions.왜? 이름이 ..
문자열(Strings) 문자열(Strings) Use single quotes '' for strings.문자열에는 싱크쿼트 '' 를 사용해 주십시오.// bad const name = "Capt. Janeway"; // good const name = 'Capt. Janeway';Strings longer than 100 characters should be written across multiple lines using string concatenation.100문자 이상의 문자열은 문자열연결을 사용해서 복수행에 걸쳐 기술할 필요가 있습니다.Note: If overused, long strings with concatenation could impact performance. jsPerf & Discussion.주의: 문자..
구조화대입(Destructuring) 구조화대입(Destructuring)Use object destructuring when accessing and using multiple properties of an object.하나의 오브젝트에서 복수의 프로퍼티를 억세스 할 때는 오브젝트 구조화대입을 이용해 주십시오.Why? Destructuring saves you from creating temporary references for those properties.왜? 구조화대입을 이용하는 것으로 프로퍼티를 위한 임시적인 참조의 작성을 줄일 수 있습니다.// bad function getFullName(user) { const firstName = user.firstName; const lastName = user.lastName; return..
배열(Arrays) 배열(Arrays)Use the literal syntax for array creation.배열을 작성 할 때는 리터럴 구문을 사용해 주십시오.// bad const items = new Array(); // good const items = [];Use Array#push instead of direct assignment to add items to an array.직접 배열에 항목을 대입하지 말고, Array#push를 이용해 주십시오.const someStack = []; // bad someStack[someStack.length] = 'abracadabra'; // good someStack.push('abracadabra');Use array spreads ... to copy arrays..
오브젝트(Objects) 오브젝트(Objects)Use the literal syntax for object creation.오브젝트를 작성할때는, 리터럴 구문을 사용하십시오.// bad const item = new Object(); // good const item = {};If your code will be executed in browsers in script context, don't use reserved words as keys. It won't work in IE8. More info. It’s OK to use them in ES6 modules and server-side code.코드가 브라우저상의 스크립트로 실행될때 예약어를 키로 이용하지 마십시오. IE8에서 작동하지 않습니다. More info하지만 E..
참조(References) 참조(References)모든 참조는 const 를 사용하고, var 를 사용하지 마십시오.Why? This ensures that you can't reassign your references, which can lead to bugs and difficult to comprehend code.왜? 참조를 재할당 할 수 없으므로, 버그로 이어지고 이해하기 어려운 코드가 되는것을 방지합니다.// bad var a = 1; var b = 2; // good const a = 1; const b = 2;If you must reassign references, use let instead of var.참조를 재할당 해야한다면 var 대신 let 을 사용하십시오.Why? let is block-scoped r..