我有 model.scan().exec() 函数将数据对象传递给处理函数。我想将返回值分配给外部上下文中的变量。我怎样才能做到这一点?
function handler (err, data) {
return data.Count;
}
await model.scan().exec(handler);
let count = // i want it to be data.Count from handler
最佳答案
我真的不知道 model.scan().exec()
做了什么,但你也许可以做这样的事情:
await model.scan().exec(() => {
const result = handler.apply(null, arguments);
});
或
await model.scan().exec((err, data) => {
const result = handler(err, data);
});
关于javascript - 如何检索函数的返回值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58859478/