forked from Badacadabra/JavaScript-Design-Patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
34 lines (28 loc) · 939 Bytes
/
Copy pathindex.ts
File metadata and controls
34 lines (28 loc) · 939 Bytes
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
namespace Mankind {
export interface Human {
sayHello(): string;
getSecretNickname(): string;
}
export class Person implements Human {
public firstName: string;
public lastName: string;
private nickname: string;
constructor(firstName: string, lastName: string, nickname: string) {
this.firstName = firstName;
this.lastName = lastName;
this.nickname = nickname;
}
public sayHello(): string {
return `Hello, ${this.firstName} ${this.lastName}!`
}
public getSecretNickname(): string {
return this.nickname;
}
}
}
import Person = Mankind.Person;
let me = new Person("Baptiste", "Vannesson", "Bada");
console.log(me.firstName, me.lastName); // OK
console.log(me.sayHello()); // OK
// console.log(me.nickname); Oops! Undefined!
console.log(me.getSecretNickname()); // OK