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

前端 未结 8 1985
囚心锁ツ
囚心锁ツ 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 17:01

    To fix your issue, i have made few changes in bla.js and it is working,

    var foo= function (req, res, next) {
      console.log('inside foo');
      return ("foo");
    }
    
    var  bar= function(req, res, next) {
      this.foo();
    }
    module.exports = {bar,foo};
    

    and no modification in app.js

    var bla = require('./bla.js');
    console.log(bla.bar());
    
    0 讨论(0)
  • 2020-11-30 17:05
    const Service = {
      foo: (a, b) => a + b,
      bar: (a, b) => Service.foo(a, b) * b
    }
    
    module.exports = Service
    
    0 讨论(0)
提交回复
热议问题