본문 바로가기

분류 전체보기

(135)
Hoisting Hoistingvar 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). It's important to know why typeof is no longer safe.14.1 var 선언은 할당이 없이 스코프의 선두에 hoist 됩니다. const 와 let 선언은Temporal Dead Zones (TDZ) 라고 불리는 새로운 컨셉의 혜택을 받고 있습니다. 이것은 왜 typeof 는 더이상 안전하지 않은가를 알고있는 것이 중요합니다.// we know ..
변수(Variables) 변수(Variables)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.변수를 선언 할 때는 항상 const 를 사용해 주십시오. 그렇게 하지 않으면 글로벌 변수로 선언됩니다. 글로벌 namespace 를 오염시키지 않도록 캡틴플래닛도 경고하고 있습니다.// bad superPower = new SuperPower(); // good const superPower = new SuperPower();Use one const declaration per vari..
이터레이터와 제너레이터(Iterators and Generators) Don't use iterators. Prefer JavaScript's higher-order functions like map() and reduce() instead of loops like for-of.iterators를 이용하지 마십시오. for-of 루프 대신에 map() 과 reduce() 와 같은 JavaScript 고급함수(higher-order functions)를 이용해 주십시오.Why? This enforces our immutable rule. Dealing with pure functions that return values is easier to reason about than side-effects.왜? 고급함수는 immutable(불변)룰을 적용합니다. side effect..
모듈(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..