-
Notifications
You must be signed in to change notification settings - Fork 130
/
Copy pathClasses_101.ts
45 lines (32 loc) · 999 Bytes
/
Classes_101.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
// RUN: deno run Playground/Demos/Classes_101.ts
class Bender {
protected name: string;
protected isFemale: boolean;
protected element: string;
constructor(name: string, isFemale: boolean, element: string) {
this.name = name;
this.isFemale = isFemale;
this.element = element;
// console.log('bender', this);
}
public introduce() {
console.log(`"Hi, I am ${this.name}. I'm from the ${this.element} nation!"`);
}
}
class EarthBender extends Bender {
protected specialty?: string;
constructor(name: string, isFemale: boolean, specialty?: string) {
super(name, isFemale, 'Earth');
this.specialty = specialty;
// console.log('EarthBender', this);
}
public earthbend() {
console.log(`${this.name} lifts the ground beneath ${this.isFemale ? 'her' : 'him'}!`);
}
}
const toph = new EarthBender('Toph', true, 'metal');
const bumi = new EarthBender('Bumi', false);
toph.introduce();
toph.earthbend();
bumi.introduce();
bumi.earthbend();