gpt4 book ai didi

node.js - 在函数内部导出函数

转载 作者:太空宇宙 更新时间:2023-11-03 23:00:38 25 4
gpt4 key购买 nike

app.js

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

module.exports = {a}

index.js

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

我想要得到输出“hello”,但我收到错误可以调用未定义的属性b请帮忙获取结果

最佳答案

试试这个

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

关于node.js - 在函数内部导出函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49063320/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com