주산들 - 자판기 온보딩 프로젝트#17
Conversation
|
|
||
| if (uni < 44032 || uni > 55203) return null; | ||
|
|
||
| return (uni - 44032) % 28 != 0; |
There was a problem hiding this comment.
가능하면 거의 모든 경우에 != 대신 !==와 같은 엄격한 연산자를 사용하는 버릇을 들이는 게 좋습니다.
| if (typeof word !== "string") return null; | ||
|
|
||
| let lastLetter = word[word.length - 1]; | ||
| let uni = lastLetter.charCodeAt(0); | ||
|
|
||
| if (uni < 44032 || uni > 55203) return null; |
There was a problem hiding this comment.
- 반환하는 자료형이 설명과 다릅니다.
44032,55203에 대한 설명이 없습니다. 한국어의 범위를 찾는다는 건 알겠지만, 가능하다면 이 부분에 변수를 새로 선언하거나 주석을 추가하여 위 숫자가 임의의 값처럼 보이지 않도록 하는 게 중요합니다.
const startOfKorean = 44032; // 한국어 첫 글자 '가'의 코드
const endOfKorean = 55203; // 한국어 마지막 글자 '힣'의 코드
There was a problem hiding this comment.
넵!! 평소에 주석을 잘 달려고 노력하는 편인데 깜빡했네요 ㅠㅠ 신경쓰겠습니다!
반환하는 자료형도 수정하도록 하겠습니다!
| let lastLetter = word[word.length - 1]; | ||
| let uni = lastLetter.charCodeAt(0); |
There was a problem hiding this comment.
논란의 여지가 있는 선택이기는 하지만, 변수 선언은 기본을 const라고 생각하는 게 좋습니다. 의도치 않은 실수를 예방할 수 있다는 점, 성능의 이득이 있을 가능성이 있다는 점 등의 이유가 있습니다. 코드의 가독성 측면에서도 변할 가능성이 있는 변수와 변할 가능성이 없는 변수는 구분하여 선언해두면 코드를 읽을 때 조금 더 문맥을 이해하고 읽게 됩니다.
변경될 가능성이 있을 때는 let 그렇지 않을 때는 기본적으로 const를 사용해보세요.
There was a problem hiding this comment.
넵!! 기본적으로 const를 사용하는 습관을 들이도록 하겠습니다!! ㅎㅎ
| <div class="insert_return_space"> | ||
| <input | ||
| type="text" | ||
| data-type="number" |
There was a problem hiding this comment.
type="number"를 사용하지 않는 이유가 있을까요?
심지어 min="0"은 type="number"일 때만 유효할텐데요.
There was a problem hiding this comment.
앗 원래 number로 했었는데 숫자값 중간에 콤마 찍는 로직을 넣으면서 이것저것 해보다가 실수한것 같습니다 😂 수정하겠습니다!!
| const cursorPosition = target.selectionStart; | ||
|
|
||
| // 원본 값에서 숫자만 추출 | ||
| const originalValue = target.value; |
There was a problem hiding this comment.
type="number"였으면 valueAsNumber 속성을 사용할 수 있습니다.
|
|
||
| /** | ||
| * item button에서 mouseup 했을 때 실행되는 함수 | ||
| * @param {event} event |
There was a problem hiding this comment.
{event} 대신 {MouseEvent}를 사용하면 에디터에서 TypeScript 타입 힌트를 조금 더 잘 받을 수 있습니다.
| const calculatedValue = currentMoney - event.currentTarget.value; | ||
| moneyInputOriginValue = calculatedValue; | ||
| moneyInput.value = calculatedValue.toLocaleString(); | ||
| const adj = checkBatchimEnding(event.currentTarget.name) ? "을" : "를"; |
There was a problem hiding this comment.
작은 i18n 관련 팁인데 조사 처리의 어려움이 느껴질 때는 변하지 않을 부분을 추가하면 됩니다. 예를 들어, 여기서는 ${event.currentTarget.name} 상품을 구매했습니다.라고 해도 되겠네요. :)
There was a problem hiding this comment.
앗 안그래도 그런 생각은 했었는데 최대한 요구사항이랑 비슷하게 구현하려다보니 이렇게 된 것 같습니다 😁
참고하겠습니다!
| moneyInputOriginValue = calculatedValue; | ||
| moneyInput.value = calculatedValue.toLocaleString(); | ||
| const adj = checkBatchimEnding(event.currentTarget.name) ? "을" : "를"; | ||
| logArea.innerHTML += `${event.currentTarget.name + adj} 구매했습니다.<br/>`; |
There was a problem hiding this comment.
이렇게 br로 줄바꿈을 할 거면 pre 태그로 로그 영역을 구분하고 줄바꿈을 사용하는 편이 더 낫지 않았을까요?
| const insertInput = document.querySelector("#insertMoney"); | ||
| const moneyInput = document.querySelector("#currentMoney"); |
There was a problem hiding this comment.
입력 버튼은 전역에 있는데 똑같이 변하지 않을 input 버튼들은 함수 안에 있는 이유가 있을까요?
There was a problem hiding this comment.
음.. 함수 안에서 사용할 element들이니 내부에 선언해두는게 코드를 읽고 이해하기 편하지 않을까 생각해서 그렇게 했었습니다.
그런데 같은 선언이 반복되기도 하고 어차피 변하지 않을 요소들이니 전역으로 빼서 정리하는 쪽으로 수정하도록 하겠습니다!!
| const currentMoney = Number(moneyInput.value.replace(/[^0-9.]/g, "")); | ||
| moneyInput.value = (currentMoney + insertMoney).toLocaleString(); |
There was a problem hiding this comment.
moneyInput의 엘리먼트를 가져오고, 문자열을 파싱해서 현재값을 가져오고, 값을 설정하고, 로그를 추가하는 코드가 반복되는 데 줄일 수 있는 방법은 없을까요?
| // 계산 및 log 출력 | ||
| const currentMoney = moneyInputProxy.value; | ||
| const insertedMoney = event.currentTarget.value; | ||
| if (currentMoney - insertedMoney > 0) { |
There was a problem hiding this comment.
이 부분에 버그가 있습니다. 금액이 딱 맞을 때 제품을 못 사요...
1차 리뷰 수정 사항 😃