导出函数内的函数

问题描述 投票:1回答:1

app.js

var a = function(){
      var b = function(){
          console.log("hello")
      }
}

module.exports = {a}

index.js

console.log(require("./app.js").a().b())

我想得到输出“你好”但我得到错误can call property b of undefined请帮助获得结果

node.js node-modules
1个回答
3
投票

试试这个

var a = function () {
    var b = function () {
        console.log("hello")
    }
    return {b:b};
}
© www.soinside.com 2019 - 2024. All rights reserved.