-
Notifications
You must be signed in to change notification settings - Fork 72
/
5_classes.ts
69 lines (54 loc) · 1.05 KB
/
5_classes.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
class Typescript {
version: string
constructor(version: string) {
this.version = version
}
info(name: string) {
return `[${name}]: Typescript version is ${this.version}`
}
}
// class Car {
// readonly model: string
// readonly numberOfWheels: number = 4
//
// constructor(theModel: string) {
// this.model = theModel
// }
// }
class Car {
readonly numberOfWheels: number = 4
constructor(readonly model: string) {}
}
// ==============
class Animal {
protected voice: string = ''
public color: string = 'black'
constructor() {
this.go()
}
private go() {
console.log('Go')
}
}
class Cat extends Animal {
public setVoice(voice: string): void {
this.voice = voice
}
}
const cat = new Cat()
cat.setVoice('test')
console.log(cat.color)
// cat.voice
// =====================
abstract class Component {
abstract render(): void
abstract info(): string
}
class AppComponent extends Component {
render(): void {
console.log('Component on render')
}
info(): string {
return 'This is info';
}
}