Function Destructuring

Jeong Ha Seung·2021년 11월 29일

ES6

목록 보기
3/9
function saveSettings(settings) {
  console.log(settings);
}

saveSettings({
  followAlert: true,
  unfollowAlert: true,
  mrkAlert: true,
  themeColor: "green"
});

function saveSettings2({ notifications, color: { theme } }) {
  console.log(notifications, theme);
}

saveSettings2({
  notifications: {
    follow: true,
    alert: true,
    mkt: false
  },
  color: {
    theme: "blue"
  }
});

saveSettings function 인자로 followAlert,unfollowAlert,mrkAlert,themeColor를 다 때려박는 것보다 saveSettings function을 호출할 때 키,값을 인자로 하면 코드가 더 간결해진다.

profile
블로그 이전했습니다. https://morethan-haseung-log.vercel.app

0개의 댓글