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

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

    You can also save a reference to module's global scope outside the (module.)exports.somemodule definition:

    var _this = this;
    
    exports.somefunction = function() {
       console.log('hello');
    }
    
    exports.someotherfunction = function() {
       _this.somefunction();
    }
    

提交回复
热议问题