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

前端 未结 8 2002
囚心锁ツ
囚心锁ツ 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

    You can also do this to make it more concise and readable. This is what I've seen done in several of the well written open sourced modules:

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

提交回复
热议问题