Rest Parameters 나머지 매개변수
인자가 가변적으로 들어올 때 사용할 수 있는 변수실제 배열로 받아서 사용가능//개선전코드function sumTotal() { return Array.from(arguments).reduce( (acc, curr) => acc + curr );}//개선된코드funcion sumTotal(...args) { //rest parameters로 들어오면 배열이기 때문에 Array.from사용할 필요 없음 return args.reduce( (acc, curr) => acc + curr );}sumTotal(1,2,3,4,5,6,7,8,9)//개선된 코드의 장점= 추가인자를 받을 수 있다.function sumTotal(initValue, ...args) { console.info(i..
복잡한 인자 관리하기
복잡한 인자를 관리할때 1. 객체로 사용하기function createCar(name, brand, color, type) { return { name, brand, color, type }}function createCar({name, brand, color, type}) { return { name, brand, color, type }}첫번째 인자는 중요하고 나머지는 옵션이다는걸 명시적으로 보여줌 function createCar(name, { brand, color, type}) { return { name, brand, color, type ..