Skip to content

Commit 848fe3e

Browse files
committed
Update typescript-basics.md
1 parent c841261 commit 848fe3e

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

TypeScript/Basics/typescript-basics.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,48 @@ interface IService {
160160
---
161161

162162
## Classes
163+
164+
- **Modifiers** <br>
165+
166+
```ts
167+
class Example {
168+
constructor(a: number, b: number) {
169+
this.a = a;
170+
this.b = b;
171+
}
172+
173+
/* prevents assignments to the field outside
174+
of the constructor */
175+
readonly a: number;
176+
177+
/* visible only inside classes inherited from
178+
the current class (not from outside) */
179+
protected b: number;
180+
181+
/* visible only inside current class
182+
(not from inherited and outside) */
183+
private secret = "hello";
184+
185+
/* allows access without creating an instance
186+
of the class may be supplemented by modifiers */
187+
static sayHello() {
188+
console.log("Hello!");
189+
}
190+
}
191+
```
192+
193+
```ts
194+
// Extending a class
195+
class NewExmaple extends Example {
196+
constructor(a: number, b: number, c: number) {
197+
super(a, b);
198+
this.c = c;
199+
}
200+
201+
c: number;
202+
203+
sayHello(name: string) {
204+
console.log(`Hello ${name}`);
205+
}
206+
}
207+
```

0 commit comments

Comments
 (0)