-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5_classes.ts
More file actions
67 lines (54 loc) · 1.2 KB
/
5_classes.ts
File metadata and controls
67 lines (54 loc) · 1.2 KB
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
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 nemberOfWheels: number = 4;
//
// constructor(theModel: string) {
// this.model = theModel;
// }
// }
//above expression is equal to bottom!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
class Car {
readonly nemberOfWheels: number = 4;
constructor(readonly model: string) {
this.model = model;
}
}
//=============================
class Animal {
protected voice: string = ""; //cant use in instance like cat but use it in class Cat
public color: string = "black";
private go() {
//only for Animal
console.log("GO");
}
}
class Cat extends Animal {
public setVoice(voice: string) {
this.voice = voice;
}
}
const cat = new Cat();
cat.setVoice("test");
console.log(cat.color);
//==================Abstracts
abstract class Component {
abstract render(): void;
abstract info(): string;
}
class AppComponent extends Component {
render(): void {
console.log("Component on render");
}
info(): string {
return "Info";
}
}