forked from ryouaki/ECMAScript2016-Design-Patterns
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Command.js
51 lines (42 loc) · 1013 Bytes
/
Command.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
'use strict';
class Invoker {
constructor() {
console.log('Invoker Class created');
}
storeCommand(command) {
this.command = command;
console.log('Invoker.storeCommand invoked');
}
}
class Command {
constructor() {
console.log('Command Class created');
}
execute() {
console.log('Command.execute invoked');
}
}
class ConcreteCommand extends Command {
constructor(receiver, state) {
super();
this.receiver = receiver;
console.log('ConcreteCommand Class created');
}
execute() {
console.log('ConcreteCommand.execute invoked');
this.receiver.action();
}
}
class Receiver {
constructor() {
console.log('Receiver Class created');
}
action() {
console.log('Receiver.action invoked');
}
}
var invoker = new Invoker();
var receiver = new Receiver();
var command = new ConcreteCommand(receiver);
invoker.storeCommand(command);
invoker.command.execute();