Solution: Inject Configuration into a Decorator
Build a decorator factory that injects a configurable prefix into log messages for different modules.
We'll cover the following...
We'll cover the following...
Solution explanation
Lines 2–6: We define
fetchOrder, a mock async function representing a service call. It resolves with an order object after a short delay.Lines 9–18: We create
createLogger(prefix), a decorator factory.It accepts a
prefixstring and returns a new decorator function.That decorator wraps any target function and logs both before and after ...