Created
August 31, 2025 22:02
-
-
Save ianjosephwilson/ace8b81c1379985a45a6e143b548f711 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Engine() { | |
| let self = {running: false, radius: 15}; | |
| return function (msg) { | |
| if (msg === 'turnOn') { | |
| self.running = true; | |
| } else if (msg === 'turnOff') { | |
| self.running = false; | |
| } else if (msg === 'setRadius') { | |
| self.radius = parseInt(arguments[1], 10); | |
| } else if (msg === 'turnOff') { | |
| self.running = false; | |
| } else if (msg === 'printStatus') { | |
| console.log(`STATUS: Engine is ${self.running ? 'on' : 'off'} and radius is ${self.radius}`); | |
| } else { | |
| throw `Invalid method ${msg}` | |
| } | |
| } | |
| } | |
| engine1 = Engine() | |
| engine1('printStatus') | |
| engine1('turnOn') | |
| engine1('printStatus') | |
| engine1('turnOff') | |
| engine1('printStatus') | |
| engine1('setRadius', 100) | |
| engine1('printStatus') |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Should output something like