Guest User

Untitled

a guest
Jan 19th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. class CustomError extends Error {
  2. constructor(message: string) {
  3. super(`Lorem "${message}" ipsum dolor.`);
  4. this.name = 'CustomError';
  5. }
  6. }
  7. throw new CustomError('foo');
  8.  
  9. class FooError extends Error {
  10. constructor(m: string) {
  11. super(m);
  12.  
  13. // Set the prototype explicitly.
  14. Object.setPrototypeOf(this, FooError.prototype);
  15. }
  16.  
  17. sayHello() {
  18. return "hello " + this.message;
  19. }
  20. }
  21.  
  22. class CustomError extends Error {
  23. constructor(message?: string) {
  24. // 'Error' breaks prototype chain here
  25. super(message);
  26. // restore prototype chain
  27. // (alternatively use Object.setPrototypeOf if you have an ES6 environment.)
  28. this.__proto__ = new.target.prototype;
  29.  
  30. }
  31. }
Add Comment
Please, Sign In to add comment