From: Jonas Sicking [[email protected]] > Note that > > ```js > (new DOMError) instanceof Error; > ``` > > returns false. So the DOM does do the "strongly discouraged" thing. Is this > ok or bad?
This is horrible! I had no idea! It should definitely derive from `Error`. > Also, the DOM does not create a new class for each different value of .name. > > I.e. you can get a DOMError whose .name is "NetworkError" or "AbortError". > > In fact, there are no defined situations where the DOM creates DOMError > objects whose .name is "DOMError". > > Again, is this ok or is it bad practice? This seems bad, although in practice not nearly as bad as the broken inheritance. (I guess because getting `name` correct is subtle; many user-space custom errors do not do so, so you can't always rely on it.) In an ideal world, I think you could do a few things: - A hierarchy, where e.g. `NetworkError` derives from `DOMError` derives from `Error`, and all have the correct `name` properties. - A reform, where `DOMError` derives from `Error` and both have the correct `name` properties; but, specific `DOMError` instances thrown by certain APIs can have a `code` property containing strings like `"NetworkError"`. > DOMError even has a constructor which allows setting .name to anything: new > DOMError(name, message); This seems quite bad: error constructors always (in ES)/almost always (in user space) take `message` as their first parameter, with other parameters beyond that being introduced by various user-space errors. _______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

