How to avoid cyclic dependency?


#1

I have two files:

a.coffee
b  = require 'b'
a = 
  func: ->
    b.func()
  otherFunc: ->
    # ...
module.exports = a
b.coffee
a = require 'a'
b =  
  func: ->
    a.otherFunc()
module.exports = b

And it doesn’t work.

b.coffee is called only from a.coffee.

Files are obviously more complex.

How should I solve it? I can put into one file, but it doesn’t look like real solution.


#2

Probably this situation means that there is something in the application design that should be changed. Here you can find more information about dependency cycles.

Hope this helps!