Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CustomError extends Error {
- constructor(message: string) {
- super(`Lorem "${message}" ipsum dolor.`);
- this.name = 'CustomError';
- }
- }
- throw new CustomError('foo');
- class FooError extends Error {
- constructor(m: string) {
- super(m);
- // Set the prototype explicitly.
- Object.setPrototypeOf(this, FooError.prototype);
- }
- sayHello() {
- return "hello " + this.message;
- }
- }
- class CustomError extends Error {
- constructor(message?: string) {
- // 'Error' breaks prototype chain here
- super(message);
- // restore prototype chain
- // (alternatively use Object.setPrototypeOf if you have an ES6 environment.)
- this.__proto__ = new.target.prototype;
- }
- }
Add Comment
Please, Sign In to add comment