Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Javascript's one is a little bit different in that you are renaming the destructured variable - it's not a function-specific thing - whereas Swift's version is a property of the function.

e.g.

  const user = {id: "123"};
  const { id } = user;          // This extracts the `id` field
  const { id: userId } = user;  // This also extracts the `id` field, but renames it to userId
  console.log(userId)


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: