-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy path7-closure.js
More file actions
31 lines (24 loc) · 482 Bytes
/
Copy path7-closure.js
File metadata and controls
31 lines (24 loc) · 482 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
'use strict';
// Closure: class factory
const createServerClass = (dependencies) => {
class Server {
constructor() {
const { Logger } = dependencies;
this.logger = new Logger();
}
shutdown() {
this.logger.log('Shutting down...');
}
}
return Server;
};
// Usage
class Logger {
constructor() {
return console;
}
}
const Server = createServerClass({ Logger });
const server = new Server();
server.shutdown();
console.log('Bye!');