JS Built-ins
Modulesintermediate

Avoiding Circular Dependencies

Circular dependencies (A imports B, B imports A) can cause issues β€” one module gets an incomplete export. The fix is to extract shared code to a third module, or restructure so dependencies flow one way. Simulate by using a dependency injection pattern instead of direct references.

πŸ’‘ Hints (4)
  • β€’ Accept logger as a parameter to createService (dependency injection)
  • β€’ Return an object with a process method
  • β€’ The process method should call logger.log(data)
  • β€’ This pattern avoids circular dependencies by passing dependencies explicitly