- Convert a class-based object to a factory that uses closures for private state
- Encapsulate internal state using function scope
- Write and run zero-dependency tests using Node.js
- Separate program execution from test execution
Reimplement the Car class as a function factory that uses closures to keep position and speed private. No code outside the Car function should need modification.
Run tests:
make test
Run the race animation:
make run
The project includes inline assertions that exercise the Car API. make test runs the assertions and exits. make run executes the race animation after the tests pass.
- Replace the Car class with a factory function
Car(acceleration, topSpeed) - Ensure position and speed are not publicly accessible
- Keep API unchanged.
update()andgetPosition()should still function as methods - Do not use the
classkeyword