Call a “local” function within module.exports from another function in module.exports?

前端 未结 8 2007
囚心锁ツ
囚心锁ツ 2020-11-30 16:24

How do you call a function from within another function in a module.exports declaration?

app.js
var bla = require(\'./bla.js\');
console.log(bl         


        
8条回答
  •  醉话见心
    2020-11-30 16:42

    Another option, and closer to the original style of the OP, is to put the object you want to export into a variable and reference that variable to make calls to other methods in the object. You can then export that variable and you're good to go.

    var self = {
      foo: function (req, res, next) {
        return ('foo');
      },
      bar: function (req, res, next) {
        return self.foo();
      }
    };
    module.exports = self;
    

提交回复
热议问题