6-8. 매개변수 객체 만들기
적용 시점
함수가 여러 개의 매개변수를 받는 경우
절차
적당한 데이터 구조가 아직 마련되어 있지 않다면 새로 만든다.
테스트한다.
함수 선언 바꾸기로 새 데이터 구조를 매개변수로 추가한다.
테스트한다.
함수 호출 시 새로운 데이터 구조 인스턴스를 넘기도록 수정한다. 하나씩 수정할 때마다 테스트한다.
기존 매개변수를 사용하던 코드를 새 데이터 구조의 원소를 사용하도록 바꾼다.
다 바꿨다면 기존 매개변수를 제거하고 테스트한다.
예시
❌Before
const getClothesInfo =
(clothesType: string, clothesCategory: string, lowPrice: number; highPrice: number) => {
// 비즈니스 로직
}
...
const clothesType = '반바지';
const clothesCategory = '남성복';
const lowPrice = 40000;
const highPrice = 60000;
const res = getClothesInfo(clothesType, clothesCategory, lowPrice, highPrice);
⭕After
const getClothesInfo =
(filteredValue: {clothesType: string, clothesCategory: string, lowPrice: number; highPrice: number}) => {
// 비즈니스 로직
}
...
const filteredValue = {
clothesType: '반바지',
clothesCategory: '남성복',
lowPrice: 40000,
highPrice: 60000,
}
const res = getClothesInfo(filteredValue);
Last updated