node.js - 如何在传递函数中返回值 (Node.js)
问题描述
我正在尝试将父函数中的变量设置为 Node.js 中的导入和嵌套函数。
家长
const child = require('./child')
function init() {
second()
let def = abc
console.log(def) // Expected log: 15
// Actual log: abc is not defined
}
function second() {
return child.third()
}
init()
孩子
exports.third = () => {
let abc = 15
return abc
}
如何正确返回 的值,abc
以便可以设置和登录init()
?
解决方案
只需abc = second()
在你的init()
街区做
推荐阅读
- android - 如何使用`sdkmanager`下载最新的`com.google.android.gms`?
- javascript - 使用 Nightwatch.js 检查 JSON 文件中的所有书籍是否存在于网页上
- python - 无法将 Python 列表中的数据插入 SQL
- ajax - JSF Ajax 工作平台依赖
- php - 如何使用 PHP 在 while 循环中显示单列?
- karate - 无法将 java 代码字符串变量重用于空手道中的另一个请求
- go - 用于 solaris/sparc 的 gccgo 上的 filebeat/libbeat 编译器
- python - 添加更多元素时,while循环不起作用
- python - 遍历 1 列,添加到新列
- apache-kafka-connect - Kafka 连接器的健康检查