In other words, why isn’t DOMException like AggregateError, EvalError, etc?
Both expressions evaluate to true:
Object.getPrototypeOf(DOMException) === Function.prototype
Object.getPrototypeOf(DOMException.prototype) === Error.prototype
I used to think the following generalization has no counterexamples:
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, the above generalization holds for the following X,Y pairs
- HTMLElement, Element
- AggregateError, Error
- AsyncFunction, Function
- Node, EventTarget
- Element, Node
- RTCError, DOMException
The only case I know of in which the generalization fails is when X = DOMException and Y = Error.
Is there a deeper reason why the DOMException constructor itself cannot have the Error constructor as its [[Prototype]]?