JS Error 클래스에

class Error {
  ...
  throw() {
    throw this
  }
}

이런 메소드 있으면 편할 것 같은데 왜 없지? 예를 들면:

# 현재
const user = findUser();
if (!user) {
  throw new Error("Not found user");
}

# `throw` 메소드
const user = findUser() ?? new Error("Not found user").throw();

이렇게 쓸 수도 있고 이름 별로면 raise 써도 되고 TC39 에 한번 제안해볼까...

3

If you have a fediverse account, you can quote this note from your own instance. Search https://hackers.pub/ap/notes/0197ee85-86cb-7c82-9d48-d60f9e72233a on your instance and quote it. (Note that quoting is not supported in Mastodon.)