javascript - Nodejs Cyclic Dependency with Revealing Module Pattern -


i've been running issue lately , looking solution. below basic setup.

in c.js, empty object. got around putting var a=require('./a.js') inside function (cfunction) needs access module a's methods. best way go this?

thanks, david


main.js

var = require('./a.js'); 

a.js

module.exports = (function() {     var b = require('./b.js');      function afunction() {         console.log("afunction");     }      return {         afunction: afunction     };  })(); 

b.js

module.exports = (function(){     var c = require('./c.js');      function bfunction(){         console.log('bfunction');     }      return {         bfunction: bfunction     };  })(); 

c.js

module.exports = (function(){     var = require('./a.js');     console.log(a); //empty object      function cfunction(){         a.afunction(); //undefined         console.log('cfunction');     }      return {         cfunction: cfunction     };  })(); 


Comments