Инструменты пользователя

Инструменты сайта


works:programmer:js:custom-error

CustomError класс

CommonJS CJS

CustomError.js
function CustomError() {
    const instance = Reflect.construct(Error, arguments);
    Reflect.setPrototypeOf(instance, Reflect.getPrototypeOf(this));
    return instance;
}
CustomError.prototype = Object.create(Error.prototype, {
    constructor: {
        value: Error,
        enumerable: false,
        writable: true,
        configurable: true
    }
});
Reflect.setPrototypeOf(CustomError, Error);
module.exports = CustomError;

EcmaScriptModule ESM

CustomError.js
class CustomError extends Error {
  constructor(...args) {
    super(args)
  }
}
CustomError.constructor.name = 'CustomError'
export default CustomError
works/programmer/js/custom-error.txt · Последнее изменение: 2024/09/11 14:48 — tuxapuk

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki