File tree Expand file tree Collapse file tree 3 files changed +174
-174
lines changed
1-js/10-error-handling/2-custom-errors Expand file tree Collapse file tree 3 files changed +174
-174
lines changed Original file line number Diff line number Diff line change 1
1
``` js run untrusted
2
- class FormatError extends SyntaxError {
3
- constructor (message ) {
4
- super (message );
2
+ class ChybaForm átu extends SyntaxError {
3
+ constructor (zpr á va ) {
4
+ super (zpráva );
5
5
this .name = this .constructor .name ;
6
6
}
7
7
}
8
8
9
- let err = new FormatError ( " formatting error " );
9
+ let chyba = new ChybaForm á tu ( " chyba formátování " );
10
10
11
- alert ( err .message ); // formatting error
12
- alert ( err .name ); // FormatError
13
- alert ( err .stack ); // stack
11
+ alert ( chyba .message ); // chyba formátování
12
+ alert ( chyba .name ); // ChybaFormátu
13
+ alert ( chyba .stack ); // zásobník
14
14
15
- alert ( err instanceof SyntaxError ); // true
15
+ alert ( chyba instanceof SyntaxError ); // true
16
16
```
Original file line number Diff line number Diff line change @@ -2,21 +2,21 @@ importance: 5
2
2
3
3
---
4
4
5
- # Inherit from SyntaxError
5
+ # Dědění ze třídy SyntaxError
6
6
7
- Create a class ` FormatError ` that inherits from the built-in ` SyntaxError ` class .
7
+ Vytvořte třídu ` ChybaFormátu ` , která je zděděna ze zabudované třídy ` SyntaxError ` .
8
8
9
- It should support ` message ` , ` name ` and ` stack ` properties .
9
+ Měla by podporovat vlastnosti ` message ` , ` name ` a ` stack ` .
10
10
11
- Usage example :
11
+ Příklad použití :
12
12
13
13
``` js
14
- let err = new FormatError ( " formatting error " );
14
+ let chyba = new ChybaForm á tu ( " chyba formátování " );
15
15
16
- alert ( err .message ); // formatting error
17
- alert ( err .name ); // FormatError
18
- alert ( err .stack ); // stack
16
+ alert ( chyba .message ); // chyba formátování
17
+ alert ( chyba .name ); // ChybaFormátu
18
+ alert ( chyba .stack ); // zásobník
19
19
20
- alert ( err instanceof FormatError ); // true
21
- alert ( err instanceof SyntaxError ); // true (because inherits from SyntaxError)
20
+ alert ( chyba instanceof ChybaFormátu ); // true
21
+ alert ( chyba instanceof SyntaxError ); // true (protože je zděděna ze SyntaxError)
22
22
```
You can’t perform that action at this time.
0 commit comments