-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path9-5-Order.js
67 lines (54 loc) Β· 1.08 KB
/
9-5-Order.js
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
/**
* p348 μμ
*/
let _repositoryData;
export function initialize() {
_repositoryData = {};
_repositoryData.customers = new Map();
}
export function registerCustomer(id) {
if (!_repositoryData.customers.has(id)) {
_repositoryData.customers.set(id, new Customer(id));
}
return findCustomer(id);
}
export function findCustomer(id) {
return _repositoryData.customers.get(id);
}
initialize();
class Order {
#number;
#customer;
constructor(data) {
this.#number = data.number;
this.#customer = registerCustomer(data.customer);
// λ€λ₯Έ λ°μ΄ν°λ₯Ό μ½μ΄ λ€μΈλ€.
}
get customer() {
return this.#customer;
}
}
class Customer {
#id;
constructor(id) {
this.#id = id;
}
get id() {
return this.#id;
}
}
/**
* μμ μ€νμ μν μμμ μ½λ
*/
const data = {
number: 111,
customer: 123,
};
const order = new Order(data);
const data2 = {
number: 222,
customer: 123,
};
const order2 = new Order(data);
console.log(order.customer.id, order2.customer.id);
console.log(Object.is(order.customer, order2.customer));