Implement a `createApp()` with `use(plugin)` and `start()`. Plugins are functions that receive the app context and can add properties or methods.
Problem Statement
Implement a `createApp()` with `use(plugin)` and `start()`. Plugins are functions that receive the app context and can add properties or methods.
Complexity
Time Complexity: -
Space Complexity: -
Hints
š” Hint 1:
Plugins follow a convention: plugin(context) modifies the context.
š” Hint 2:
Store plugins and apply them in order on start().
š” Hint 3:
Each plugin receives the app context object and can add/modify properties.
ā
Solution:
```javascript
function createApp() {
const plugins = [];
const context = {};
return {
use(plugin) { plugins.push(plugin); },
start() {
plugins.forEach(p => p(context));
return context;
}
};
}
```