Object.setPrototypeOf(this, RequestValidationError.prototype)
好问题。简而言之,如果您的代码仅在现代浏览器(支持ES6)中运行,则有必要手动设置原型。 MDN的参考:
this
在这里是一些有用的链接以获取详细信息:https://developer.mozilla.org/en-us/docs/web/javascript/reference/global_objects/error
https://github.com/microsoft/typescript/wiki/faq#why-doesnt-externding-built-ins-ins-like-error-array-array-Array-Array-and-map-work
https://developer.mozilla.org/en-us/docs/web/javascript/reference/reference/operators/new.target