Timeline for What's a good way to extend Error in JavaScript?
Current License: CC BY-SA 4.0
6 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jun 5 at 12:04 | comment | added | SePeF |
@ZachYoung Omitting setPrototypeOf() works in JS running in the browser and in node, but not when using a transpiler like Babel. For an explanation see the "Explanation" part of this answer stackoverflow.com/a/43595019/9299798
|
|
Jun 4 at 16:34 | history | edited | SePeF | CC BY-SA 4.0 |
deleted 68 characters in body
|
Nov 30, 2022 at 17:55 | comment | added | Zach Young |
Is Object.setPrototypeOf(this, new.target.prototype) really necessary? I was following along with Corman's answer to this Q, which doesn't have the Object.setProto... line, and my custom error is both an instance of itself (err1 instanceOf MyError ) and its super (err1 instanceOf Error ).
|
|
Sep 21, 2022 at 8:39 | comment | added | NerdyDeeds |
THANK you! Error.captureStackTrace(this, this.constructor) ! Duh, now I look at it, but that was eluding me for hours. Good gods I feel like I've just spent 45 minutes reading a dozen+ pedantically- masturbatory code treatises before finally getting here. Well done! Also, thanks for chiming in years after the fact, too (this is not sarcasm; I really DO appreciate it, lol). Most people see an old question with a buncha answers and brush on past. Your 2 cents were a price I'd happily have paid at twice the cost.
|
|
Dec 21, 2021 at 8:19 | comment | added | Steve Moretz | The only answer that works, in dept. | |
Apr 23, 2021 at 13:20 | history | answered | SePeF | CC BY-SA 4.0 |