导入.js
exports.getConfig = function() {
return api.getConfig();
};
测试.js
// Aanmaken lightBridge
obj = reflector.getObj();
console.log(obj);
// Toon alle lichten
obj.getConfig().then(function(config) {
console.log(config);
}).done();
在最后一个片段中,它使用了以下函数 当我调用 getConfig() 时,我希望获得变量配置中的输出。现在的问题是,当我想记录变量测试时,我收到了未定义的消息。
如果我 console.log(config) 而不是 return config;它工作得很好。看起来很奇怪。
当我想使用它时,输出结果就像 varia.getConfig() => config 的输出。
最佳答案
测试仅存在于您的函数中,而不存在于外部。您可以尝试这样的方法,但它可能会很脏。
var test;
exports.getConfig = function() {
api.getConfig(function(err, config) {
if (err) throw err;
test = config;
});
关于node.js - 函数中的函数返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36712287/