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

슈티를 함께 만들 팀을 만들고 있습니다. 관심 있으신 분, 또는 잘 모르겠지만 이야기를 나눠보고 싶은 분도 bgl@gwyng.com으로 편하게 연락주세요.

Hi, I'm who's behind Fedify, Hollo, BotKit, and this website, Hackers' Pub!

Fedify, Hollo, BotKit, 그리고 보고 계신 이 사이트 Hackers' Pub을 만들고 있습니다.

FedifyHolloBotKit、そしてこのサイト、Hackers' Pubを作っています。

嗨,我是 FedifyHolloBotKit 以及這個網站 Hackers' Pub 的開發者!