Why is DOMException different from AggregateError, EvalError, and others in terms of its prototype chain?
Both of these statements are true:
Object.getPrototypeOf(DOMException) === Function.prototype
Object.getPrototypeOf(DOMException.prototype) === Error.prototype
I once believed that the following rule always applied:
If
- X and Y are constructor functions, and
- Y is not the Object() constructor, and
- X.prototype has Y.prototype as its [[Prototype]] object Then
- X has Y as its [[Prototype]] object
For example, this rule holds for pairs like:
- HTMLElement, Element
- AggregateError, Error
- AsyncFunction, Function
- Node, EventTarget
- Element, Node
- RTCError, DOMException
The only exception I know of is when X = DOMException and Y = Error.
Is there a specific reason why the DOMException constructor cannot have the Error constructor as its [[Prototype]]?