반응형
ES2026
-
Javascript ES17(ECMAScript 2026) 문법정리카테고리 없음 2026. 9. 10. 07:13
has → get → set 세 줄이 한 줄이 된다Map으로 카운터나 그룹핑을 만들 때마다 똑같은 세 줄을 썼다. 키가 있으면 꺼내 쓰고 없으면 기본값을 넣는, 아무 판단도 들어 있지 않은 분기다.// before — 있으면 꺼내고 없으면 넣는다const counts = new Map();for (const w of words) { if (counts.has(w)) counts.set(w, counts.get(w) + 1); else counts.set(w, 1);}// after — getOrInsert가 그 분기를 삼킨다const counts = new Map();for (const w of words) counts.set(w, counts.getOrInsert(w, 0) + 1);그룹핑은 차이가..