Open JeGwan opened 3 years ago
function amountInvoice(startDate: Date, endDate: Date) { // ... } function amountOverdue(startDate: Date, endDate: Date) { // ... } // into function amountInvoice(dateRage: [Date, Date]) { // ... } function amountOverdue(dateRage: [Date, Date]) { // ... }
const station = { name: 'ZB1', readings: [ { temp: 47, time: '2020-11-10 09:10' }, { temp: 54, time: '2020-11-11 09:10' }, { temp: 32, time: '2020-11-12 09:10' }, { temp: 39, time: '2020-11-13 09:10' }, { temp: 22, time: '2020-11-14 09:10' }, ], } function readingsOutsideRange(station, min, max) { return station.readings.filter(r => r.temp < min || r.temp > max) } const alerts = readingsOutsideRange(station, operatingPlan.temperatureFloor, operationgPlan.temperatureCeiling) // 1. min, max를 묶어 표현하는 클래스를 만들어보자. class NumberRange { constructor(min, max) { this._data = { min, max } } get min() { return this._data.min } get max() { return this._data.max } } // 2. NumberRange 타입의 데이터를 넣을 수 있게 함수에 매개변수를 추가한다. function readingsOutsideRange(station, min, max, range) { return station.readings.filter(r => r.temp < min || r.temp > max) } // 3. 호출문엔 일단 null을 넣는다. const alerts = readingsOutsideRange(station, operatingPlan.temperatureFloor, operationgPlan.temperatureCeiling, null) // 4. 호출문을 바꾼다. const range = new NumberRange(operatingPlan.temperatureFloor, operationgPlan.temperatureCeiling) const alerts = readingsOutsideRange(station, operatingPlan.temperatureFloor, operationgPlan.temperatureCeiling, range) // 5. 기존 매개변수 사용부분을 변경한다. function readingsOutsideRange(station, range) { return station.readings.filter(r => r.temp < range.min || r.temp > range.max) } // 6. 호출부의 안쓰는 매개변수도 없앤다. const range = new NumberRange(operatingPlan.temperatureFloor, operationgPlan.temperatureCeiling) const alerts = readingsOutsideRange(station, range)
function isBigBasePrice(order) { const basePrice = order.basePrice return basePrice > 1000 } // into function isBigBasePrice(order) { return order.basePrice > 1000 }
function circum() {} // into function circumference() {}
availableVacation(employee, empleyee.grade) function availableVacation(employee, grade) { // ... } // into availableVacation(employee) function availableVacation(employee) { const grade = employee.grade }
Introduce parameter object
배경
예시
장점
절차
예시
Inline variable
배경
예시
Change function declaration
배경
예시
Replace Parameter with Query
배경
예시