Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Light = {
- isOn: false,
- turnOn() {
- this.isOn = true
- return this
- },
- turnOff() {
- this.isOn = false
- return this
- }
- }
- const CommandFactory = ({ receiver, execute, unexecute }) => ({
- receiver,
- execute,
- unexecute
- })
- const LightInvokerFactory = ({ on, off }) => ({
- on: CommandFactory(on),
- off: CommandFactory(off)
- })
- const myLightInvoker = LightInvokerFactory({
- on: {
- receiver: Light,
- execute() {
- this.receiver.turnOn()
- return this
- },
- unexecute() {
- this.receiver.turnOff()
- return this
- }
- },
- off: {
- receiver: Light,
- execute() {
- this.receiver.turnOff()
- return this
- },
- unexecute() {
- this.receiver.turnOn()
- return this
- }
- }
- })
Add Comment
Please, Sign In to add comment