[도서]실전 리액트 프로그래밍(2)

choiuhana·2021년 9월 15일
0

중첩된 객체 비구조화

const obj = {name:'mike', mother: {name: 'sara'}};
const {
  name,
  mother: {name: motherName},
} = obj;
console.log(motherName) // sara
console.log(mother) //err

별칭을 이용한 객체와 배열의 속성값 할당

const obj = {};
const arr = [];

({foo: obj.prop, bar: arr[0]} = {foo:123, bar:true})
console.log(obj) // { prop: 123 }
console.log(arr) // [ true ]

함수에 필수값을 표현하는 방법

function required(){
  throw new Error('no parameter');
}

function printLog(a = required()) {
  console.log({ a })
}

printLog(10); // { a : 10 }
printLog(); // 에러 발생: no parameter

throw MDN Link

나머지 매개변수

function printLog(a,...res){
  console.log({a, rest });
}
printLog(1,2,3); // {a:1, rest: [2,3]};

명명된 매개변수

// 함수를 작성할때 매개변수의 기본값 또는 이름을 짓는것이 유지보수나 협업에 도움이 될듯 하다
const result = getValues({ numbers, greaterThan: 5, lessThan: 25});
profile
만드는 사람도 사용하는 사람도 편하고 만족하는 '것'을 추구하는 프론트엔드 개발자

0개의 댓글