How to deal with cyclic dependencies in Node.js

后端 未结 13 2161
别那么骄傲
别那么骄傲 2020-11-22 04:36

I\'ve been working with nodejs lately and still getting to grips with the module system so apologies if this is an obvious question. I want code roughly like the following b

13条回答
  •  甜味超标
    2020-11-22 05:11

    An other method I've seen people do is exporting at the first line and saving it as a local variable like this:

    let self = module.exports = {};
    
    const a = require('./a');
    
    // Exporting the necessary functions
    self.func = function() { ... }
    

    I tend to use this method, do you know about any downsides of it?

提交回复
热议问题