-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path8-pattern.js
More file actions
33 lines (27 loc) · 628 Bytes
/
Copy path8-pattern.js
File metadata and controls
33 lines (27 loc) · 628 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
'use strict';
class Person {
constructor(name, surname) {
this.name = name;
this.surname = surname;
}
getFullName() {
const { name = '', surname = '' } = this;
return name + ' ' + surname;
}
}
class PersonProxy {
constructor(person) {
this.person = person;
}
getFullName() {
let fullName = this.person.getFullName();
if (fullName.startsWith(' ') || fullName.endsWith(' ')) {
fullName = fullName.trim();
}
return fullName;
}
}
// Usage
const proxy = new PersonProxy(new Person('Marcus', 'Antonin'));
const fullName = proxy.getFullName();
console.dir({ fullName });