-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path7-gof-deep.js
More file actions
59 lines (47 loc) · 862 Bytes
/
7-gof-deep.js
File metadata and controls
59 lines (47 loc) · 862 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
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
'use strict';
class Point {
#x;
#y;
constructor(x, y) {
this.#x = x;
this.#y = y;
}
move(x, y) {
this.#x += x;
this.#y += y;
}
clone() {
return new Point(this.#x, this.#y);
}
toString() {
return `(${this.#x}, ${this.#y})`;
}
}
class Line {
#start;
#end;
constructor(start, end) {
this.#start = start;
this.#end = end;
}
move(x, y) {
this.#start.move(x, y);
this.#end.move(x, y);
}
clone() {
const start = this.#start.clone();
const end = this.#end.clone();
return new Line(start, end);
}
toString() {
return `[${this.#start}, ${this.#end}]`;
}
}
// Usage
const p1 = new Point(0, 0);
const p2 = new Point(10, 20);
const line = new Line(p1, p2);
console.log(line.toString());
const cloned = line.clone();
cloned.move(2, 3);
console.log(cloned.toString());